lib/redis_cluster/pool.rb in redis_cluster-0.2.6 vs lib/redis_cluster/pool.rb in redis_cluster-0.2.7
- old
+ new
@@ -22,24 +22,35 @@
# other_options:
# asking
# random_node
def execute(method, args, other_options, &block)
- return send(method, args.first) if Configuration::SUPPORT_MULTI_NODE_METHODS.include?(method.to_s)
+ return send(method, args, &block) if Configuration::SUPPORT_MULTI_NODE_METHODS.include?(method.to_s)
key = key_by_command(method, args)
raise NotSupportError if key.nil?
node = other_options[:random_node] ? random_node : node_by(key)
node.asking if other_options[:asking]
node.execute(method, args, &block)
end
- def keys(glob = "*")
+ def keys(args, &block)
+ glob = args.first
on_each_node(:keys, glob).flatten
end
+ # Now mutli & pipelined conmand must control keys at same slot yourself
+ # You can use hash tag: '{foo}1'
+ def multi(args, &block)
+ random_node.execute :multi, args, &block
+ end
+
+ def pipelined(args, &block)
+ random_node.execute :pipelined, args, &block
+ end
+
private
def node_by(key)
slot = Slot.slot_by(key)
@nodes.find {|node| node.has_slot?(slot) }
@@ -49,10 +60,10 @@
@nodes.sample
end
def key_by_command(method, args)
case method.to_s.downcase
- when 'info', 'multi', 'exec', 'slaveof', 'config', 'shutdown'
+ when 'info', 'exec', 'slaveof', 'config', 'shutdown'
nil
else
return args.first
end
end