From 4115f344818ddfb97abf3ec43b3b7246fc0049cc Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Tue, 20 Feb 2024 11:28:33 +0900 Subject: [PATCH] fix: unwatch should be called only if an error occurred during the transaction --- lib/redis_client/cluster/optimistic_locking.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/redis_client/cluster/optimistic_locking.rb b/lib/redis_client/cluster/optimistic_locking.rb index 4f11d6fc..8db9a9dd 100644 --- a/lib/redis_client/cluster/optimistic_locking.rb +++ b/lib/redis_client/cluster/optimistic_locking.rb @@ -18,9 +18,10 @@ def watch(keys) @router.handle_redirection(node, retry_count: 1) do |nd| nd.with do |c| c.call('WATCH', *keys) - reply = yield(c, slot) + yield(c, slot) + rescue StandardError c.call('UNWATCH') - reply + raise end end end