Skip to content

Commit

Permalink
Cluster determine slot command name need upper
Browse files Browse the repository at this point in the history
The judgment of the name is all uppercase, for example:
    L970: if command in ("EVAL", "EVALSHA"):
  • Loading branch information
yangbodong22011 committed Sep 18, 2023
1 parent 19b55c6 commit c455e04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions redis/asyncio/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ async def _determine_slot(self, command: str, *args: Any) -> int:
# EVAL/EVALSHA.
# - issue: https://github.com/redis/redis/issues/9493
# - fix: https://github.com/redis/redis/pull/9733
if command in ("EVAL", "EVALSHA"):
if command.upper() in ("EVAL", "EVALSHA"):
# command syntax: EVAL "script body" num_keys ...
if len(args) < 2:
raise RedisClusterException(
Expand All @@ -604,7 +604,7 @@ async def _determine_slot(self, command: str, *args: Any) -> int:
if not keys:
# FCALL can call a function with 0 keys, that means the function
# can be run on any node so we can just return a random slot
if command in ("FCALL", "FCALL_RO"):
if command.upper() in ("FCALL", "FCALL_RO"):
return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)
raise RedisClusterException(
"No way to dispatch this command to Redis Cluster. "
Expand Down
6 changes: 3 additions & 3 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,11 +967,11 @@ def determine_slot(self, *args):
# redis server to parse the keys. Besides, there is a bug in redis<7.0
# where `self._get_command_keys()` fails anyway. So, we special case
# EVAL/EVALSHA.
if command in ("EVAL", "EVALSHA"):
if command.upper() in ("EVAL", "EVALSHA"):
# command syntax: EVAL "script body" num_keys ...
if len(args) <= 2:
raise RedisClusterException(f"Invalid args in command: {args}")
num_actual_keys = args[2]
num_actual_keys = int(args[2])
eval_keys = args[3 : 3 + num_actual_keys]
# if there are 0 keys, that means the script can be run on any node
# so we can just return a random slot
Expand All @@ -983,7 +983,7 @@ def determine_slot(self, *args):
if keys is None or len(keys) == 0:
# FCALL can call a function with 0 keys, that means the function
# can be run on any node so we can just return a random slot
if command in ("FCALL", "FCALL_RO"):
if command.upper() in ("FCALL", "FCALL_RO"):
return random.randrange(0, REDIS_CLUSTER_HASH_SLOTS)
raise RedisClusterException(
"No way to dispatch this command to Redis Cluster. "
Expand Down

0 comments on commit c455e04

Please # to comment.