Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Redis WATCH to prefixed complex commands #1572

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
31 changes: 31 additions & 0 deletions t/unit/transport/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,37 @@ def test_global_keyprefix_pubsub(self, mock_execute_command):
'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:

Expand Down