如何使用Cyclone和Redis进行身份验证

时间:2012-05-14 10:37:15

标签: python redis twisted 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()
    print "commit=", repr(r)

由于

2 个答案:

答案 0 :(得分:1)

Cyclone redis客户端有一个auth方法可以发送密码,在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.

答案 1 :(得分:0)

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

但是,它在自动重新连接方面效果不佳,因为Connection方法中未实现身份验证。这意味着重新连接后它不会自动重新进行身份验证。

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