Sha256: dbf6703a1496d56cfcef9acda3992b2f55640e72c968243c12e046636d8f6af0

Contents?: true

Size: 762 Bytes

Versions: 4

Compression:

Stored size: 762 Bytes

Contents

module RedisRing
  module Client

    class ShardConnectionPool

      attr_reader :metadata, :password, :db

      def initialize(metadata, password, db)
        @metadata = metadata
        @password = password
        @db = db
        @connections = {}
      end

      def connection(shard_number)
        @connections[shard_number] ||= new_connection_to_shard(shard_number)
      end

      protected

      def new_connection_to_shard(shard_number)
        shard_metadata = metadata.shard(shard_number)
        new_connection(shard_metadata.host, shard_metadata.port, db, password)
      end

      def new_connection(host, port, db, password)
        Redis.new(:host => host, :port => port, :db => db, :password => password)
      end

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis_ring_client-0.0.4 lib/redis_ring/client/shard_connection_pool.rb
redis_ring_client-0.0.3 lib/redis_ring/client/shard_connection_pool.rb
redis_ring_client-0.0.2 lib/redis_ring/client/shard_connection_pool.rb
redis_ring_client-0.0.1 lib/redis_ring/client/shard_connection_pool.rb