如何使用Cyclone和Redis进行认证

2024-04-28 23:59:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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()
    print "commit=", repr(r)

谢谢


Tags: 代码服务器redis身份验证webhost密码客户端
2条回答

cyclone redis客户端有一个auth方法,您可以将密码发送到该方法,并在redis.conf中设置了该密码

def auth(self, password):
    """
    Simple password authentication if enabled
    """
    return self.execute_command("AUTH", password)

但是在使用redis auth之前要非常小心。它并不真正被认为是安全的(按设计),它应该主要用于保护实例,防止配置错误导致客户端连接到错误的数据库,而不是作为一种安全方法。在

从redis config doc:

^{pr2}$

cyclone中的redis驱动程序是txredisapi,它确实支持身份验证(还有许多其他功能)。这里提到:https://github.com/fiorix/txredisapi/blob/master/README.md#authentication

但是,它不能很好地处理自动重新连接,因为身份验证没有在Connection方法中实现。这意味着它在重新连接后不会自动重新认证。在

它可以实现,但人们似乎没有使用它。在

相关问题 更多 >