Skip to content

Commit 086efb2

Browse files
Cluster determine slot command name need upper (#2919)
The judgment of the name is all uppercase, for example: L970: if command in ("EVAL", "EVALSHA"):
1 parent 509c77c commit 086efb2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

redis/asyncio/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ async def _determine_slot(self, command: str, *args: Any) -> int:
588588
# EVAL/EVALSHA.
589589
# - issue: https://github.com/redis/redis/issues/9493
590590
# - fix: https://github.com/redis/redis/pull/9733
591-
if command in ("EVAL", "EVALSHA"):
591+
if command.upper() in ("EVAL", "EVALSHA"):
592592
# command syntax: EVAL "script body" num_keys ...
593593
if len(args) < 2:
594594
raise RedisClusterException(
595595
f"Invalid args in command: {command, *args}"
596596
)
597-
keys = args[2 : 2 + args[1]]
597+
keys = args[2 : 2 + int(args[1])]
598598
# if there are 0 keys, that means the script can be run on any node
599599
# so we can just return a random slot
600600
if not keys:
@@ -604,7 +604,7 @@ async def _determine_slot(self, command: str, *args: Any) -> int:
604604
if not keys:
605605
# FCALL can call a function with 0 keys, that means the function
606606
# can be run on any node so we can just return a random slot
607-
if command in ("FCALL", "FCALL_RO"):
607+
if command.upper() in ("FCALL", "FCALL_RO"):
608608
return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)
609609
raise RedisClusterException(
610610
"No way to dispatch this command to Redis Cluster. "

redis/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,11 +967,11 @@ def determine_slot(self, *args):
967967
# redis server to parse the keys. Besides, there is a bug in redis<7.0
968968
# where `self._get_command_keys()` fails anyway. So, we special case
969969
# EVAL/EVALSHA.
970-
if command in ("EVAL", "EVALSHA"):
970+
if command.upper() in ("EVAL", "EVALSHA"):
971971
# command syntax: EVAL "script body" num_keys ...
972972
if len(args) <= 2:
973973
raise RedisClusterException(f"Invalid args in command: {args}")
974-
num_actual_keys = args[2]
974+
num_actual_keys = int(args[2])
975975
eval_keys = args[3 : 3 + num_actual_keys]
976976
# if there are 0 keys, that means the script can be run on any node
977977
# so we can just return a random slot
@@ -983,7 +983,7 @@ def determine_slot(self, *args):
983983
if keys is None or len(keys) == 0:
984984
# FCALL can call a function with 0 keys, that means the function
985985
# can be run on any node so we can just return a random slot
986-
if command in ("FCALL", "FCALL_RO"):
986+
if command.upper() in ("FCALL", "FCALL_RO"):
987987
return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)
988988
raise RedisClusterException(
989989
"No way to dispatch this command to Redis Cluster. "

0 commit comments

Comments
 (0)