https://github.com/leffss/ScrapyRedisBloomFilterBlockCluster
https://pypi.org/project/scrapy-redis-sentinel/ scrapy 使用redis 哨兵
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哨兵
# _*_ coding:utf-8 _*_
_
import redis
from redis.sentinel import Sentinel
from celery import Celery
# celery_app = Celery("ApiInterface", broker='redis://root:123@172.20.0.252:6079/9') #单机版
# CELERYD_OPTS = "--time-limit=7200 -E --loglevel=DEBUG"
celery_app=Celery("app") #集群哨兵版
celery_app.conf.broker_url = 'sentinel://root:redis@localhost:26079;sentinel://root:redis@localhost:26080;sentinel://root:redis@localhost:26081'
celery_app.conf.broker_transport_options = { 'master_name': "local-master" }
本文介绍了如何在Python应用中使用Redis Sentinel集群,包括Scrapy与Celery两个场景。通过Sentinel进行高可用配置,确保数据的稳定存储和任务的可靠执行。详细配置代码已给出。
541

被折叠的 条评论
为什么被折叠?



