Sha256: 1ba8cf2b88c7f7b9d19ca54e3bca270a0de4a46b4285865ea749544d071fd17f

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 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)
        connection, conn_id = @connections[shard_number]
        shard_metadata = metadata.shard(shard_number)
        unless conn_id == shard_metadata.to_sym
          connection = new_connection(shard_metadata.host, shard_metadata.port, db, password)
          conn_id = shard_metadata.to_sym
          @connections[shard_number] = [connection, conn_id]
        end
        connection
      end

      protected

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

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redis_ring_client-0.1.2 lib/redis_ring/client/shard_connection_pool.rb
redis_ring_client-0.1.1 lib/redis_ring/client/shard_connection_pool.rb
redis_ring_client-0.1.0 lib/redis_ring/client/shard_connection_pool.rb