summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Cecile <dancecile@gmail.com>2022-07-11 11:51:01 -0400
committerAsif Saif Uddin <auvipy@gmail.com>2022-07-14 22:56:41 +0600
commit4440c649e0497e74791f65474d684595542ec36a (patch)
tree65e526873c4d207bb22e01c3ddc945f62fcf77af
parent674a645356227576170ebb378c903a9445a384e4 (diff)
downloadkombu-4440c649e0497e74791f65474d684595542ec36a.tar.gz
Add WATCH to prefixed complex commands
-rw-r--r--kombu/transport/redis.py1
-rw-r--r--t/unit/transport/test_redis.py31
2 files changed, 32 insertions, 0 deletions
diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py
index 889a0ed2..57a5a63b 100644
--- a/kombu/transport/redis.py
+++ b/kombu/transport/redis.py
@@ -211,6 +211,7 @@ class GlobalKeyPrefixMixin:
"DEL": {"args_start": 0, "args_end": None},
"BRPOP": {"args_start": 0, "args_end": -1},
"EVALSHA": {"args_start": 2, "args_end": 3},
+ "WATCH": {"args_start": 0, "args_end": None},
}
def _prefix_args(self, args):
diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py
index d06f2959..b14408a6 100644
--- a/t/unit/transport/test_redis.py
+++ b/t/unit/transport/test_redis.py
@@ -1145,6 +1145,37 @@ class test_Channel:
'foo_/{db}.a',
)
+ @patch("redis.client.Pipeline.execute_command")
+ def test_global_keyprefix_transaction(self, mock_execute_command):
+ from kombu.transport.redis import PrefixedStrictRedis
+
+ with Connection(transport=Transport) as conn:
+ def pipeline(transaction=True, shard_hint=None):
+ pipeline_obj = original_pipeline(
+ transaction=transaction, shard_hint=shard_hint
+ )
+ mock_execute_command.side_effect = [
+ None, None, pipeline_obj, pipeline_obj
+ ]
+ return pipeline_obj
+
+ client = PrefixedStrictRedis(global_keyprefix='foo_')
+ original_pipeline = client.pipeline
+ client.pipeline = pipeline
+
+ channel = conn.channel()
+ channel._create_client = Mock()
+ channel._create_client.return_value = client
+
+ channel.qos.restore_by_tag('test-tag')
+ assert mock_execute_command is not None
+ assert mock_execute_command.mock_calls == [
+ call('WATCH', 'foo_unacked'),
+ call('HGET', 'foo_unacked', 'test-tag'),
+ call('ZREM', 'foo_unacked_index', 'test-tag'),
+ call('HDEL', 'foo_unacked', 'test-tag')
+ ]
+
class test_Redis: