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')

 

 

轉載於:https://www.cnblogs.com/shihaokiss/p/8466915.html

來源:https://blog.csdn.net/weixin_34161032/article/details/94210359

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章