Skip to content

Issue with cache_config with 7.4.0 #4009

@QHivert

Description

@QHivert

Hello,

I was using 7.1.1 and after an update to 7.4.0, see this bug.

Here an example:

from redis import Redis,
from redis.cache import CacheConfig

conn_str =  "redis://username:password@redis:6379/?decode_responses=Yes&protocol=3"
redis = Redis.from_url(redis_connstring, cache_config=CacheConfig())

# Fill up a sorted set
redis.zadd("myset", {"foo": 1})
redis.zadd("myset", {"bar": 2})

#First time it works because redis actually do the command
total_count = redis.zcard("myset")

#Second time it raises an error because redis try to get the info from the cache instead of doing the command
total_count = redis.zcard("myset")

The exception raises:

 File "/workspace/app/manager/cache/ClientRedis.py", line 257, in zset_paginate_hashes
    total_count = redis.zcard(zset_key_default)
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/commands/core.py", line 4731, in zcard
    return self.execute_command("ZCARD", name, keys=[name])
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/client.py", line 716, in execute_command
    return self._execute_command(*args, **options)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/client.py", line 736, in _execute_command
    result = conn.retry.call_with_retry(
    
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/retry.py", line 120, in call_with_retry
    return do()
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/client.py", line 737, in <lambda>
    lambda: self._send_command_parse_response(
    
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/client.py", line 682, in _send_command_parse_response
    return self.parse_response(conn, command_name, **options)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/client.py", line 780, in parse_response
    response = connection.read_response()
  File "/home/quentin/.cache/pypoetry/virtualenvs/sogo-xS3fZVNL-py3.13/lib/python3.13/site-packages/redis/connection.py", line 1715, in read_response
    bytes_saved=len(res)

The problem is in this function read_response ->

def read_response(

The first time:

  • self._current_command_cache_key = CacheKey(command='ZCARD', redis_keys=('user_sessions:activity',), redis_args=('ZCARD', 'user_sessions:activity'))
  • Not in self._cache so the command is done
  • response = 2
  • store in cache

Next time:

  • self._current_command_cache_key = CacheKey(command='ZCARD', redis_keys=('user_sessions:activity',), redis_args=('ZCARD', 'user_sessions:activity'))
  • In self._cache get the cache reponse
  • res = 2
  • after at line 1714: record_csc_network_saved(bytes_saved=len(res) ) -> crash because res is a int.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions