【发布时间】:2019-03-27 15:58:54
【问题描述】:
我的缓存设置:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/1',
'OPTIONS': {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
}
}
主机是127.0.0.1,端口是6379,数据库是1。
我想像这样使用redis_connection 添加数据:
from django_redis import get_redis_connection
redis_conn = get_redis_connection('default')
redis_conn.set('somekey', 'somevalue')
所以redis数据库现在有数据了,我可以通过:
redis_conn.get('somekey')
但我无法通过django.core.cache.cache 得到它,尽管数据库中存在数据:
from django.core.cache import cache
cache.get('somekey') #return None
如果必须使用conn设置数据,使用cache获取数据,该怎么办?
【问题讨论】:
标签: django redis django-redis