redis的数据是在内存中的,所以访问会比较快。
1.使用django-redis
官方文档
2.项目中的settings.py
CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379/1", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", } }, "session": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379/2", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.Defaul�����,�ǿ���ҹtClient", } },}SESSION_ENGINE = "django.contrib.sessions.backends.cache"SESSION_CACHE_ALIAS = "session" # 调用session
3.登录redis上查看
1.get <key>2.keys3.ttl <key>