django + redis 使用
结合 django-redis
配置
django settings
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0", # redis地址
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient", # 设置默认连接
"PASSWORD": "12456" # 设置连接密码
}
}
}
使用
django cache
from django.core.cache import cache
a = ['a', 'b', 'c']
# 添加
cache.set('s', a)
# 获取
cache.get('s')
django_redis
from django_redis import get_redis_connection
r = get_redis_connection()
r.redis 命令
get_redis_connection()
r.redis 命令