Closed github-yxb closed 4 years ago
Thanks for your report!
AUTH
to Sentinel, but because it sends ROLE
to Redis before AUTH
. I've fixed it in #122, could you please check that it works now? I've tested it with following snippet:from twisted.internet import defer
from twisted.internet.task import react
from txredisapi import Sentinel
@defer.inlineCallbacks
def main(reactor):
redis = Sentinel([('localhost', 26379)]).master_for('test', password='qweasdzxc')
response = yield redis.get('hello')
print(response)
yield redis.disconnect()
react(main)
master_for
returns SentinelConnectionFactory
because it means "Redis connection that asks Sentinel for the master/slave addr and then connects to it".
self.sentinels
uses regular RedisFactory
because connections to Sentinel is just regular connections without "ask sentinel for the real address" magic.
我测试了txredisapi的问sentinel功能, 发现sentinel并不能正常工作,当我使用
txredisapi.Sentinel([("xxxxxxxx", 7379)], password = "1234")
txredisapi会向sentinel发送AUTH指令,但其实sentinel并不支持AUTH指令, 所以sentinel返回错误,导到不能获取到master。 这个password选项其实应该是给master或slave使用的。 还有代码上的疑惑self.sentinels = [ lazyConnection(host, port, **connection_kwargs) for host, port in sentinel_addresses ]
在sentinel初始化时创建了连向sentinel的factory,但应该是使用SentinelConnectionFactory吧。
def master_for(self, service_name, factory_class=SentinelConnectionFactory, dbid=None, poolsize=1, **connection_kwargs): factory = factory_class(sentinel_manager=self, service_name=service_name, is_master=True, uuid=None, dbid=dbid, poolsize=poolsize, **connection_kwargs) return self._connect_factory_and_return_handler(factory, poolsize)
而获取master时,应该当返回RedisFactory而不是SentinelConnectionFactory。