Skip to content

Commit

Permalink
fix: add missing commands to prefix
Browse files Browse the repository at this point in the history
Add missing DEL, RPUSH, RPOP and SREM commands to the list of commands to prefix.

Also, this commit refactors the prefixing logic a bit to make it simpler.
  • Loading branch information
gabor-boros authored and auvipy committed Aug 27, 2021
1 parent cad7a88 commit 24b0820
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ class GlobalKeyPrefixMixin:
"LLEN",
"LPUSH",
"PUBLISH",
"RPUSH",
"RPOP",
"SADD",
"SREM",
"SET",
"SMEMBERS",
"ZADD",
Expand All @@ -206,6 +209,7 @@ class GlobalKeyPrefixMixin:
]

PREFIXED_COMPLEX_COMMANDS = {
"DEL": {"args_start": 0, "args_end": None},
"BRPOP": {"args_start": 0, "args_end": -1},
"EVALSHA": {"args_start": 2, "args_end": 3},
}
Expand All @@ -222,13 +226,10 @@ def _prefix_args(self, args):
args_end = self.PREFIXED_COMPLEX_COMMANDS[command]["args_end"]

pre_args = args[:args_start] if args_start > 0 else []
post_args = []

if args_end is not None:
post_args = args[args_end:]
elif args_end < 0:
post_args = args[len(args):]
else:
post_args = []

args = pre_args + [
self.global_keyprefix + str(arg)
Expand Down
15 changes: 15 additions & 0 deletions t/unit/transport/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,21 @@ def test_prefix_simple_args(self):
f"{self.global_keyprefix}fake_key"
]

def test_prefix_delete_args(self):
prefixed_args = self.mixin._prefix_args([
"DEL",
"fake_key",
"fake_key2",
"fake_key3"
])

assert prefixed_args == [
"DEL",
f"{self.global_keyprefix}fake_key",
f"{self.global_keyprefix}fake_key2",
f"{self.global_keyprefix}fake_key3",
]

def test_prefix_brpop_args(self):
prefixed_args = self.mixin._prefix_args([
"BRPOP",
Expand Down

0 comments on commit 24b0820

Please sign in to comment.