django 框架中应用 redis 集群(亲测)
生活随笔
收集整理的這篇文章主要介紹了
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 主機ip3. 重啟redis ps aux | grep redis kill -9 redis-pid redis-server redis.conf4. 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')轉載于:https://www.cnblogs.com/shihaokiss/p/8466915.html
來源:https://blog.csdn.net/weixin_34161032/article/details/94210359
總結
以上是生活随笔為你收集整理的django 框架中应用 redis 集群(亲测)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配置Django实现数据库读写分离
- 下一篇: django连接redis(文章看着不错