diff --git a/redis/asyncio/cluster.py b/redis/asyncio/cluster.py index 84407116ed..65e1bd02ac 100644 --- a/redis/asyncio/cluster.py +++ b/redis/asyncio/cluster.py @@ -588,13 +588,13 @@ 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( f"Invalid args in command: {command, *args}" ) - keys = args[2 : 2 + args[1]] + keys = args[2 : 2 + int(args[1])] # if there are 0 keys, that means the script can be run on any node # so we can just return a random slot if not keys: @@ -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. " diff --git a/redis/cluster.py b/redis/cluster.py index cba62de077..0347893205 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -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 @@ -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. "