Sha256: 2556f684de08be7a53d42cb63c83d0f5f32e596d8ab5d1e2e34fa39fe3099ef0

Contents?: true

Size: 604 Bytes

Versions: 4

Compression:

Stored size: 604 Bytes

Contents

# frozen_string_literal: true

require 'redis'
require 'forwardable'

module AsyncStorage
  class RedisPool
    extend Forwardable
    def_delegator :@connection, :with

    module ConnectionPoolLike
      def with
        yield self
      end
    end

    def initialize(connection)
      if connection.respond_to?(:with)
        @connection = connection
      else
        if connection.respond_to?(:client)
          @connection = connection
        else
          @connection = ::Redis.new(*[connection].compact)
        end
        @connection.extend(ConnectionPoolLike)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
async_storage-0.0.4 lib/async_storage/redis_pool.rb
async_storage-0.0.3 lib/async_storage/redis_pool.rb
async_storage-0.0.2 lib/async_storage/redis_pool.rb
async_storage-0.0.1 lib/async_storage/redis_pool.rb