import redis
from redis.sentinel import Sentinel
python 中使用 redis哨兵
class RedisClient(object):
'''初始化Redis数据库'''
def __init__(self,TYPE, host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD,db=0):
# self.db = redis.StrictRedis(host=host, port=port, password=password, decode_responses=True, db=db)
self.db = Sentinel([('172.20.0.252', 26079), ('172.20.0.252', 26080),('172.20.0.252', 26081)], socket_timeout=0.5)
if TYPE=='write':
self.db = self.db.master_for('local-master', socket_timeout=0.5,password='redis' ,db=db)
if TYPE=='read':
self.db = self.db.slave_for('local-master', socket_timeout=0.5, password='redis',db=db)
celery 中使用 redis哨兵
# _*_