我使用的是redis客户端的cyclone。
没有密码就可以连接到服务器,这很棒,但是我怎么用密码连接到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()
print "commit=", repr(r)谢谢
发布于 2012-05-14 18:52:04
cyclone redis客户端有一个在redis.conf中设置了密码后可以向其发送密码的auth方法
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.发布于 2012-06-11 14:13:48
cyclone中的redis驱动程序是txredisapi,它确实支持身份验证(以及其他许多功能)。这里提到:https://github.com/fiorix/txredisapi/blob/master/README.md#authentication
但是,它不能很好地处理自动重新连接,因为身份验证不是在Connection方法中实现的。这意味着它不会在重新连接后自动重新进行身份验证。
它可以实现,但人们似乎并没有使用它。
https://stackoverflow.com/questions/10581725
复制相似问题