django-redis-cache icon indicating copy to clipboard operation
django-redis-cache copied to clipboard

Error with redis 3.0.0

Open andialbrecht opened this issue 6 years ago • 6 comments

About an hour ago the redis package was released in version 3.0.0. Since then I see the following error when using django-redis-cache:

>>> from django.core.cache import cache
>>> cache.get("foo", None)
Traceback (most recent call last):
  File "/home/andi/.local/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis_cache/backends/base.py", line 33, in wrapped
    return method(self, client, key, *args, **kwargs)
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis_cache/backends/base.py", line 256, in get
    value = client.get(key)
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis/client.py", line 1207, in get
    return self.execute_command('GET', name)
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis/client.py", line 754, in execute_command
    connection.send_command(*args)
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis/connection.py", line 619, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis/connection.py", line 659, in pack_command
    for arg in imap(self.encoder.encode, args):
  File "/home/andi/.envs/app/lib/python3.6/site-packages/redis/connection.py", line 124, in encode
    "byte, string or number first." % typename)
redis.exceptions.DataError: Invalid input of type: 'CacheKey'. Convert to a byte, string or number first.
>>> 

When downgrading redis to 2.10.6 everything works fine.

andialbrecht avatar Nov 15 '18 10:11 andialbrecht

PR #161 will fix that

drgarcia1986 avatar Nov 15 '18 14:11 drgarcia1986

This was resolved with 34dadba20a0c2345ee07419c354dae567382ada3. Thanks!

andialbrecht avatar Nov 16 '18 12:11 andialbrecht

Actually, can we open this back up as tracking for the need of Redis 3.x compatibility?

fxfitz avatar Nov 19 '18 14:11 fxfitz

There is a good discussion on this on the django-redis repo. The main issue I believe is that Redis no longer converts to a string by default. Therefore the CacheKey object needs to return a string.

https://github.com/niwinz/django-redis/issues/342

avelis avatar Nov 19 '18 20:11 avelis

I think I have a workaround by simply subclassing unicode and attaching an attribute that we can use to store the versioned key.

sebleier avatar Nov 19 '18 20:11 sebleier

Is there a timeline for bringing this code up to date? I'm getting the error below during a pip install.

django-redis-cache 1.8.1 has requirement redis==2.10.6, but you'll have redis 3.1.0 which is incompatible.

cnobile2012 avatar Feb 01 '19 18:02 cnobile2012