gpt4 book ai didi

python - django-redis 无效的数据库索引错误和 redis url 的含义

转载 作者:太空宇宙 更新时间:2023-11-04 07:55:30 25 4
gpt4 key购买 nike

我正在使用 django-redis:https://niwinz.github.io/django-redis/latest/

在设置和测试缓存时,我有一个问题。

来自:https://niwinz.github.io/django-redis/latest/#_installation

有这样的代码:

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}

当我使用这个不变的任何 LOCATION 代码作为:"LOCATION": "redis://127.0.0.1:6379/1" 时,它正在做出色地。甚至 "LOCATION": "redis://127.0.0.1:6379/2" 似乎也能正常工作。

但如果我将其更改为 "LOCATION": "redis://127.0.0.1:6379/220",

它返回无效的数据库索引错误

问题:

  1. 为什么会这样?

  2. "LOCATION": "redis://127.0.0.1:6379/parameter" 中的参数是什么意思?

这是回溯:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/test/

Django Version: 2.0.2
Python Version: 3.6.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'post',
'website']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware']



Traceback:

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django_redis\cache.py" in _decorator
32. return method(self, *args, **kwargs)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django_redis\cache.py" in get
81. client=client)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django_redis\client\default.py" in get
204. raise ConnectionInterrupted(connection=client, parent=e)

During handling of the above exception (Redis ResponseError: invalid DB index), another exception occurred:

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django\core\handlers\exception.py" in inner
35. response = get_response(request)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django\utils\deprecation.py" in __call__
93. response = self.process_request(request)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django\middleware\cache.py" in process_request
133. cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django\utils\cache.py" in get_cache_key
360. headerlist = cache.get(cache_key)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django_redis\cache.py" in _decorator
39. raise e.parent

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django_redis\client\default.py" in get
202. value = client.get(key)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\client.py" in get
976. return self.execute_command('GET', name)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\client.py" in execute_command
667. connection.send_command(*args)

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\connection.py" in send_command
610. self.send_packed_command(self.pack_command(*args))

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\connection.py" in send_packed_command
585. self.connect()

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\connection.py" in connect
493. self.on_connect()

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\connection.py" in on_connect
567. if nativestr(self.read_response()) != 'OK':

File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\redis\connection.py" in read_response
629. raise response

Exception Type: ResponseError at /test/
Exception Value: invalid DB index

最佳答案

默认情况下,Redis 服务器配置有 16 (0..15) 个共享数据库。使用数据库 0 以外的任何东西通常被认为是不好的做法。

关于python - django-redis 无效的数据库索引错误和 redis url 的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49537392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com