Python 如何使用Cyclone和Redis进行身份验证
我正在为cyclone使用redis客户端 很好,您可以不用密码连接到服务器,但我如何用密码连接到redis?如何修改以下代码以进行身份验证Python 如何使用Cyclone和Redis进行身份验证,python,redis,twisted,cyclone,Python,Redis,Twisted,Cyclone,我正在为cyclone使用redis客户端 很好,您可以不用密码连接到服务器,但我如何用密码连接到redis?如何修改以下代码以进行身份验证 t = cyclone.redis.lazyConnectionPool(host,port,db) @cyclone.web.asynchronous def on_finish(self): t = yield tt.multi() yield t.set('key', 'value') r = yield t.commit
t = cyclone.redis.lazyConnectionPool(host,port,db)
@cyclone.web.asynchronous
def on_finish(self):
t = yield tt.multi()
yield t.set('key', 'value')
r = yield t.commit()
print "commit=", repr(r)
感谢在
redis.conf
def auth(self, password):
"""
Simple password authentication if enabled
"""
return self.execute_command("AUTH", password)
但是在使用redis auth之前要非常小心。它实际上并不被认为是安全的(从设计上讲),主要用于保护实例,防止配置错误导致客户端连接到错误的数据库,而不是作为一种安全方法
从redis配置文档:
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
cyclone中的redis驱动程序是,它确实支持身份验证(以及其他许多功能)。这里提到: 但是,它不能很好地处理自动重新连接,因为身份验证没有在
连接
方法中实现。这意味着它不会在重新连接后自动重新验证
它可以实现,但人们似乎没有使用它 我不太了解那个特定的客户端,但从docuemntation来看,它应该是类似于
t=cyclone.redis.lazyConnectionPool(主机、端口、数据库);authResult=yield t.auth(myPass)