We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8ab2753 + 65ac655 commit bce3f41Copy full SHA for bce3f41
cluster/lib/redis/cluster.rb
@@ -96,6 +96,10 @@ def cluster(subcommand, *args)
96
send_command([:cluster, subcommand] + args, &block)
97
end
98
99
+ def watch(*keys, &block)
100
+ synchronize { |c| c.call_v([:watch] + keys, &block) }
101
+ end
102
+
103
private
104
105
def initialize_client(options)
cluster/redis-clustering.gemspec
@@ -47,5 +47,5 @@ Gem::Specification.new do |s|
47
s.required_ruby_version = '>= 2.7.0'
48
49
s.add_runtime_dependency('redis', s.version)
50
- s.add_runtime_dependency('redis-cluster-client', '>= 0.7.0')
+ s.add_runtime_dependency('redis-cluster-client', '>= 0.7.11')
51
cluster/test/client_transactions_test.rb
@@ -48,4 +48,25 @@ def test_cluster_client_does_not_support_transaction_by_multiple_keys
assert_nil(redis.get("key#{i}"))
52
+ def test_cluster_client_does_support_transaction_with_optimistic_locking
53
+ redis.mset('{key}1', '1', '{key}2', '2')
54
55
+ another = Fiber.new do
56
+ cli = build_another_client
57
+ cli.mset('{key}1', '3', '{key}2', '4')
58
+ cli.close
59
+ Fiber.yield
60
61
62
+ redis.watch('{key}1', '{key}2') do |tx|
63
+ another.resume
64
+ v1 = redis.get('{key}1')
65
+ v2 = redis.get('{key}2')
66
+ tx.call('SET', '{key}1', v2)
67
+ tx.call('SET', '{key}2', v1)
68
69
70
+ assert_equal %w[3 4], redis.mget('{key}1', '{key}2')
71
72
cluster/test/commands_on_transactions_test.rb
@@ -38,10 +38,29 @@ def test_unwatch
38
39
40
def test_watch
41
- assert_raises(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
42
- redis.watch('key1', 'key2')
+ assert_raises(Redis::Cluster::TransactionConsistencyError) do
+ redis.watch('{key}1', '{key}2')
43
44
45
- assert_equal 'OK', redis.watch('{key}1', '{key}2')
46
+ redis.watch('key1', 'key2') do |tx|
+ tx.call('SET', 'key1', '1')
+ tx.call('SET', 'key2', '2')
+ redis.watch('{hey}1', '{hey}2') do |tx|
+ tx.call('SET', '{key}1', '1')
+ tx.call('SET', '{key}2', '2')
+ assert_equal %w[1 2], redis.mget('{key}1', '{key}2')
test/helper.rb
@@ -174,7 +174,7 @@ def version
174
def with_acl
175
admin = _new_client
176
admin.acl('SETUSER', 'johndoe', 'on',
177
- '+ping', '+select', '+command', '+cluster|slots', '+cluster|nodes',
+ '+ping', '+select', '+command', '+cluster|slots', '+cluster|nodes', '+readonly',
178
'>mysecret')
179
yield('johndoe', 'mysecret')
180
ensure
0 commit comments