1,安装
pip3 install django-redis
2,配置
settings文件中的配置
CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", # redis的地址 "LOCATION": "redis://192.168.1.103:6379", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "CONNECTION_POOL_KWARGS": {"max_connections": 100}, # 密码 "PASSWORD": "glf123", } } }
3,视图中的使用
from django-redis import get_redis_connection #创建连接 conn_redis=get_redis_connection("default")
conn_redis.hset("name","keys","values")