Skip to content

Commit 597ef95

Browse files
authored
fix: make an error message easy to understand for the watch command (#335)
1 parent 3dba901 commit 597ef95

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/redis_client/cluster/router.rb

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics
313313

314314
# for redis-rb
315315
def send_watch_command(command)
316+
raise ::RedisClient::Cluster::Transaction::ConsistencyError, 'A block required. And you need to use the block argument as a client for the transaction.' unless block_given?
317+
316318
::RedisClient::Cluster::OptimisticLocking.new(self).watch(command[1..]) do |c, slot|
317319
transaction = ::RedisClient::Cluster::Transaction.new(
318320
self, @command_builder, node: c, slot: slot

test/redis_client/test_cluster.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def test_transaction_in_race_condition
364364
end
365365

366366
# for redis-rb
367-
def test_transaction_with_standalone_watch_command
367+
def test_transaction_with_dedicated_watch_command
368368
@client.call('MSET', '{key}1', '0', '{key}2', '0')
369369

370370
got = @client.call('WATCH', '{key}1', '{key}2') do |tx|
@@ -378,6 +378,12 @@ def test_transaction_with_standalone_watch_command
378378
assert_equal(%w[1 2], @client.call('MGET', '{key}1', '{key}2'))
379379
end
380380

381+
def test_transaction_with_dedicated_watch_command_without_block
382+
assert_raises(::RedisClient::Cluster::Transaction::ConsistencyError) do
383+
@client.call('WATCH', '{key}1', '{key}2')
384+
end
385+
end
386+
381387
def test_pubsub_without_subscription
382388
pubsub = @client.pubsub
383389
assert_nil(pubsub.next_event(0.01))

0 commit comments

Comments
 (0)