我的缓存设置:
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来获取数据,我该怎么做?