django 框架中应用 redis 集群

1. 在 setting.py 中添加 :

CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': redis主机ip + ':' + 端口号,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
},
}


2. redis 主机中的配置修改:
bind 127.0.0.1 ===》 bind 主机ip


3. 重启redis
ps aux | grep redis
kill -9 redis-pid
redis-server redis.conf

4. redis 客户端的连接 :
redis-cli -h redis主机ip -p 端口号

5. 在 django 中,redis 原生客户端的使用:
from django_redis import get_redis_connection
con = get_redis_connection("default")
con.set('key', 'value', 2*60)    # 2 分钟超时

con.get('key')
 

posted @ 2018-02-24 17:03  in_the_way  阅读(753)  评论(0编辑  收藏  举报