Invalid input of type: 'CacheKey'. Convert to a byte, string or number first.

我是在django当中使用redis出现的这个报错;

原因:django-redis和redis(python原生包)会有一个兼容的问题;

Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/django_redis/cache.py", line 32, in _decorator
    return method(self, *args, **kwargs)
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/django_redis/cache.py", line 67, in set
    return self.client.set(*args, **kwargs)
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/django_redis/client/default.py", line 142, in set
    return client.set(nkey, nvalue, nx=nx, px=timeout, xx=xx)
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/redis/client.py", line 1451, in set
    return self.execute_command('SET', *pieces)
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/redis/client.py", line 774, in execute_command
    connection.send_command(*args)
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/redis/connection.py", line 619, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/Users/jiso/workspace/TDMS_Env/lib/python3.6/site-packages/redis/connection.py", line 659, in pack_command
    for arg in imap(self.encoder.encode, args):
  File "/Users/jiso/workspace/TDMS_Env/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.

将python原生redis包降级为2.1.0即可,或者不使用django.core.cache

你可能感兴趣的:(Python)