Module: RedisRing::Client::OperationDefinitions::InstanceMethods
- Defined in:
- lib/redis_ring/client/operation_definitions.rb
Instance Method Summary collapse
- #random_shard_operation(name, *args, &block) ⇒ Object
- #scather_gather_operation(name, gather, *args, &block) ⇒ Object
- #single_connection_operation(name, keys, *args, &block) ⇒ Object
- #single_key_operation(name, first_arg, *rest) ⇒ Object
- #unsupported_operation(name) ⇒ Object
Instance Method Details
#random_shard_operation(name, *args, &block) ⇒ Object
46 47 48 49 |
# File 'lib/redis_ring/client/operation_definitions.rb', line 46 def random_shard_operation(name, *args, &block) shard_no = rand(.ring_size) return connection_pool.connection(shard_no).send(name, *args, &block) end |
#scather_gather_operation(name, gather, *args, &block) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/redis_ring/client/operation_definitions.rb', line 34 def scather_gather_operation(name, gather, *args, &block) results = [] each_connection do |conn| results << conn.send(name, *args, &block) end return send(gather, results) end |
#single_connection_operation(name, keys, *args, &block) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/redis_ring/client/operation_definitions.rb', line 51 def single_connection_operation(name, keys, *args, &block) shard_numbers = keys.map { |key| sharder.shard_for_key(key) } unless shard_numbers.uniq.size == 1 raise MultiShardOperationError.new("Multi-shard atomic operations are not allowed. Try using {shard_secifier} suffix if you really need them. Operation: #{name}, Keys: #{keys.join(', ')}") end return connection_for_key(keys.first).send(name, *args, &block) end |
#single_key_operation(name, first_arg, *rest) ⇒ Object
29 30 31 32 |
# File 'lib/redis_ring/client/operation_definitions.rb', line 29 def single_key_operation(name, first_arg, *rest) connection = connection_for_key(first_arg) return connection.send(name, first_arg, *rest) end |
#unsupported_operation(name) ⇒ Object
42 43 44 |
# File 'lib/redis_ring/client/operation_definitions.rb', line 42 def unsupported_operation(name) raise UnsupportedOperationError.new("Operation #{name} is not supported by RedisRing!") end |