Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit e267c9e

Browse files
author
KJ Tsanaktsidis
committed
Use redirection handling for pubsub/client/cluster/etc commands
These commands families were falling back to assign_node().public_send(), but we actually want to invoke the redirection handling logic for them like any other command.
1 parent 60bb509 commit e267c9e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/redis_client/cluster/router.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ def send_config_command(method, command, args, &block)
257257
case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
258258
when 'resetstat', 'rewrite', 'set'
259259
@node.call_all(method, command, args).first.then(&TSF.call(block))
260-
else assign_node(command).public_send(method, *args, command, &block)
260+
else try_send(assign_node(command), method, command, args, &block)
261261
end
262262
end
263263

264264
def send_memory_command(method, command, args, &block)
265265
case ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_subcommand(command)
266266
when 'stats' then @node.call_all(method, command, args, &block)
267267
when 'purge' then @node.call_all(method, command, args).first.then(&TSF.call(block))
268-
else assign_node(command).public_send(method, *args, command, &block)
268+
else try_send(assign_node(command), method, command, args, &block)
269269
end
270270
end
271271

@@ -274,7 +274,7 @@ def send_client_command(method, command, args, &block)
274274
when 'list' then @node.call_all(method, command, args, &block).flatten
275275
when 'pause', 'reply', 'setname'
276276
@node.call_all(method, command, args).first.then(&TSF.call(block))
277-
else assign_node(command).public_send(method, *args, command, &block)
277+
else try_send(assign_node(command), method, command, args, &block)
278278
end
279279
end
280280

@@ -287,8 +287,9 @@ def send_cluster_command(method, command, args, &block)
287287
when 'getkeysinslot'
288288
raise ArgumentError, command.join(' ') if command.size != 4
289289

290-
find_node(@node.find_node_key_of_replica(command[2])).public_send(method, *args, command, &block)
291-
else assign_node(command).public_send(method, *args, command, &block)
290+
node = find_node(@node.find_node_key_of_replica(command[2]))
291+
try_send(node, method, command, args, &block)
292+
else try_send(assign_node(command), method, command, args, &block)
292293
end
293294
end
294295

@@ -300,7 +301,7 @@ def send_script_command(method, command, args, &block) # rubocop:disable Metrics
300301
@node.call_primaries(method, command, args).first.then(&TSF.call(block))
301302
when 'exists'
302303
@node.call_all(method, command, args).transpose.map { |arr| arr.any?(&:zero?) ? 0 : 1 }.then(&TSF.call(block))
303-
else assign_node(command).public_send(method, *args, command, &block)
304+
else try_send(assign_node(command), method, command, args, &block)
304305
end
305306
end
306307

@@ -318,7 +319,7 @@ def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics
318319
when 'shardnumsub'
319320
@node.call_replicas(method, command, args).reject(&:empty?).map { |e| Hash[*e] }
320321
.reduce({}) { |a, e| a.merge(e) { |_, v1, v2| v1 + v2 } }.then(&TSF.call(block))
321-
else assign_node(command).public_send(method, *args, command, &block)
322+
else try_send(assign_node(command), method, command, args, &block)
322323
end
323324
end
324325

0 commit comments

Comments
 (0)