可视化工具:RedisDesktopManager
redis载地址:https://github.com/MSOpenTech/redis/releases。
redis-server.exe redis.windows.conf
redis-cli.exe -h 127.0.0.1 -p 6379
redis-cli # 启动客户端 set key value # 设置值 get key # 取出值
字符串、字典、列表、集合、有序集合
https://www.runoob.com/redis/redis-tutorial.html
可持久化、单线程单进程并发
pip3 install redis
import redis r = redis.Redis(host='127.0.0.1', port=6379)
import redis pool = redis.ConnectionPool(host='127.0.0.1', port=6379) r = redis.Redis(connection_pool=pool)
import redis r = redis.Redis(db=0) #第几个库总共有15个库
# 1.将缓存存储位置配置到redis中:settings.py #首先要安装依赖pip install django-redis。 CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0.1:6379", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "CONNECTION_POOL_KWARGS": {"max_connections": 100} } } } # 2.操作cache模块直接操作缓存:views.py from django.core.cache import cache # 结合配置文件实现插拔式 # 存放token,可以直接设置过期时间 cache.set('token', 'header.payload.signature', 10) # 取出token token = cache.get('token')