支持使用redis sentinel的redis连接工厂
Redis-Sentinel-Url的Python项目详细描述
redis sentinel url为redis://和redis+sentinel://url(后者)提供解析器和连接工厂 由这个包定义)。
- 支持Python2.7和3.3+
- 使用apache license 2.0授权
安装
使用pip安装:
pip install Redis-Sentinel-Url
通过Sentinel连接的URL方案
这个包定义了通过sentinel连接到redis的redis+sentinel://方案
redis+sentinel://[:password@]host:port[,host2:port2,...][/service_name[/db]][?param1=value1[¶m2=value=2&...]]
- 您可以指定多个由逗号分隔的sentinel host:port对。
- 如果提供了“服务名称”,则它用于创建默认客户机
- 服务名和数据库也可以指定为url参数(url参数优先)
- 客户端选项(redis.strictredis的关键字参数)指定为url参数
- 指定了连接到sentinel的选项(指向redis.sentinel.sentinel的关键字参数 带有前哨语前缀
- 有一个特殊的客户机类型选项来指定默认客户机应该是主客户机(默认)还是 从服务器通过Sentinel连接时的服务
基本用法
支持redis.strictredis.from_url支持的方案,也支持redis+sentinel://上述方案:
importredis_sentinel_urlsentinel,client=redis_sentinel_url.connect('redis://localhost/0')# None, StrictRedis(...)sentinel,client=redis_sentinel_url.connect('rediss://localhost/0')# None, StrictRedis(...)sentinel,client=redis_sentinel_url.connect('unix://[:password]@/path/to/socket.sock?db=0')# None, StrictRedis(...)sentinel,client=redis_sentinel_url.connect('redis+sentinel://localhost:26379,otherhost:26479/mymaster/0')# Sentinel(...), StrictRedis(...)