Class: RedisRing::Client::RingProxy
- Inherits:
-
Object
- Object
- RedisRing::Client::RingProxy
- Includes:
- OperationDefinitions
- Defined in:
- lib/redis_ring/client/ring_proxy.rb
Instance Method Summary collapse
- #connection_for_key(key) ⇒ Object
- #each_connection(&block) ⇒ Object
-
#initialize(opts = {}) ⇒ RingProxy
constructor
A new instance of RingProxy.
- #smove(source, destination, member) ⇒ Object
Methods included from OperationDefinitions
Constructor Details
#initialize(opts = {}) ⇒ RingProxy
Returns a new instance of RingProxy.
153 154 155 156 157 158 |
# File 'lib/redis_ring/client/ring_proxy.rb', line 153 def initialize(opts = {}) @zookeeper = opts[:zookeeper] || 'localhost:2181' @db = opts[:db] || 0 @password = opts[:password] @cluster_name = opts[:cluster_name] || 'redis-ring' end |
Instance Method Details
#connection_for_key(key) ⇒ Object
160 161 162 163 |
# File 'lib/redis_ring/client/ring_proxy.rb', line 160 def connection_for_key(key) shard = sharder.shard_for_key(key) return connection_pool.connection(shard) end |
#each_connection(&block) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/redis_ring/client/ring_proxy.rb', line 165 def each_connection(&block) threads = [] .ring_size.times do |shard_no| threads << Thread.new do block.call(connection_pool.connection(shard_no)) end end threads.each { |thread| thread.join } end |
#smove(source, destination, member) ⇒ Object
149 150 151 |
# File 'lib/redis_ring/client/ring_proxy.rb', line 149 def smove(source, destination, member) return single_connection_operation(:smove, [source, destination], source, destination, member) end |