redis相关
【启动】
1、修改redis.conf:
1)daemonize no修改成 daemonize yes
2)注释 bind 127.0.0.1 -::* (若不注释,仅本机可访问)
3)设置密码: requirepass [password]
2、redis根目录下执行 src/redis-server redis.conf
【停止】
1、src/redis-cli -p [port] 进入默认客户端
2、客户端中执行命令:shutdown save|nosave (参数:关闭redis服务前是否生产持久化文件)
【django配置redis】
1)安装django-redis:pip install django-redis
2)在settings中添加配置
CACHES = {
"default": {
"BACKEND":"django_redis.cache.RedisCache",
# "LOCATION": "redis://username@localhost:6379/0", # 带用户名的连接地址
"LOCATION":"redis://127.0.0.1:6379/0",
"OPTIONS": {
"CLIENT_CLASS":"django_redis.client.DefaultClient",
"CONNECTION_POOL_KWARGS": {"max_connections":20, "decode_responses":True}, # 返回默认为字节,decode_responses转为字符串
"PASSWORD":"xxxxxxx",
}
}
}