|
8 | 8 | require 'redis_client/cluster/node' |
9 | 9 | require 'redis_client/cluster/node_key' |
10 | 10 | require 'redis_client/cluster/normalized_cmd_name' |
| 11 | +require 'redis_client/cluster/transaction' |
| 12 | +require 'redis_client/cluster/optimistic_locking' |
11 | 13 |
|
12 | 14 | class RedisClient |
13 | 15 | class Cluster |
@@ -44,6 +46,7 @@ def send_command(method, command, *args, &block) # rubocop:disable Metrics/AbcSi |
44 | 46 | when 'memory' then send_memory_command(method, command, args, &block) |
45 | 47 | when 'script' then send_script_command(method, command, args, &block) |
46 | 48 | when 'pubsub' then send_pubsub_command(method, command, args, &block) |
| 49 | + when 'watch' then send_watch_command(command, &block) |
47 | 50 | when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save' |
48 | 51 | @node.call_all(method, command, args).first.then(&TSF.call(block)) |
49 | 52 | when 'flushall', 'flushdb' |
@@ -308,6 +311,17 @@ def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics |
308 | 311 | end |
309 | 312 | end |
310 | 313 |
|
| 314 | + # for redis-rb |
| 315 | + def send_watch_command(command) |
| 316 | + ::RedisClient::Cluster::OptimisticLocking.new(self).watch(command[1..]) do |c, slot| |
| 317 | + transaction = ::RedisClient::Cluster::Transaction.new( |
| 318 | + self, @command_builder, node: c, slot: slot |
| 319 | + ) |
| 320 | + yield transaction |
| 321 | + transaction.execute |
| 322 | + end |
| 323 | + end |
| 324 | + |
311 | 325 | def update_cluster_info! |
312 | 326 | @node.reload! |
313 | 327 | end |
|
0 commit comments