解决redis ResponseError: [PROXY] unsupported command select

>>> from django_redis import get_redis_connection
>>> r = get_redis_connection()
>>> r.set('test', 1)
Traceback (most recent call last):
  File "", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/redis/client.py", line 1451, in set
    return self.execute_command('SET', *pieces)
  File "build/bdist.linux-x86_64/egg/redis/client.py", line 774, in execute_command
    connection.send_command(*args)
  File "build/bdist.linux-x86_64/egg/redis/connection.py", line 619, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "build/bdist.linux-x86_64/egg/redis/connection.py", line 594, in send_packed_command
    self.connect()
  File "build/bdist.linux-x86_64/egg/redis/connection.py", line 502, in connect
    self.on_connect()
  File "build/bdist.linux-x86_64/egg/redis/connection.py", line 576, in on_connect
    if nativestr(self.read_response()) != 'OK':
  File "build/bdist.linux-x86_64/egg/redis/connection.py", line 638, in read_response
    raise response
ResponseError: [PROXY] unsupported command select 

今天redis 加入认证机制,并采用proxy链接,先看django的caches 配置:

CACHES = {
     
    "default": {
     
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://ip:6379/0",
        "OPTIONS": {
     
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "PASSWORD": "pwd",
        }
    }
}

当我将 LOCATION 的 redis库配置为0库时,不会报错,当配置为1~15库时就会报错,所以总结为proxy做了redis后面所有库的整合,默认就是0库。

你可能感兴趣的:(后端,redis)