Skip to content

Error in redis parser when using client tracking #2592

Open
@matejsp

Description

@matejsp

Version: 4.5.1

Redis Server:
redis_version:7.0.8
redis_build_id:73fe4a3beb619f6
redis_mode:cluster
os:Darwin 22.3.0 x86_64

Platform: MacOSX 13.2

Description:
When calling client.client_tracking_on(clientid=id, prefix=['foo'], bcast=True) on clustered redis parser crashes.
It works in normal client (non clustered). Same error when using with or without hiredis==2.2.2

stacktrace:

  File "/Users/myuser/projects/xxx/redis_bug.py", line 20, in <module>
    client1.client_tracking_on(clientid=id, prefix=['foo'], bcast=True)
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/commands/core.py", line 603, in client_tracking_on
    return self.client_tracking(
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/commands/core.py", line 684, in client_tracking
    return self.execute_command("CLIENT TRACKING", *pieces)
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/cluster.py", line 1074, in execute_command
    raise e
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/cluster.py", line 1047, in execute_command
    target_nodes = self._determine_nodes(
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/cluster.py", line 875, in _determine_nodes
    slot = self.determine_slot(*args)
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/cluster.py", line 945, in determine_slot
    keys = self._get_command_keys(*args)
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/cluster.py", line 912, in _get_command_keys
    return self.commands_parser.get_keys(redis_conn, *args)
  File "/Users/myuser/.virtualenvs/bitstamp38/lib/python3.8/site-packages/redis/commands/parser.py", line 105, in get_keys
    range(command["first_key_pos"], last_key_pos + 1, command["step_count"])
ValueError: range() arg 3 must not be zero

code

import time
from redis import cluster


def handler(msg):
    print('MSG: {}'.format(msg))


if __name__ == '__main__':
    # client1 = redis.client.Redis.from_url('redis://localhost:6379/0') # works
    client1 = cluster.RedisCluster.from_url('redis://localhost:6379/0')

    id = client1.client_id()

    pubsub = client1.pubsub()
    pubsub.subscribe(**{'__redis__:invalidate': handler})
    pubsub.run_in_thread(daemon=True, sleep_time=None)

    client1.client_tracking_on(clientid=id, prefix=['foo'], bcast=True)

    client1.get('fooASF')
    for i in range(10):
        client1.set('fooASF', '23423423ff')

    time.sleep(100)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions