如何在redis-py中使用pipeline设置等待响应的redis超时时间?

18
在下面的代码中,管道超时是2秒吗?
client = redis.StrictRedis(host=host, port=port, db=0, socket_timeout=2)
pipe = client.pipeline(transaction=False)
for name in namelist:
    key = "%s-%s-%s-%s" % (key_sub1, key_sub2, name, key_sub3)
    pipe.smembers(key)
pipe.execute()
在Redis中,集合"key"有很多成员。它始终返回以下错误,其中包含最后的代码:

In the redis, there are a lot of members in the set "key". It always return the error as below with the code last:


error Error while reading from socket: ('timed out',)

如果我把socket_timeout的值改为10,就会返回ok。
"socket_timeout"参数不是指连接超时吗?但它看起来像是响应超时。
redis-py版本为2.6.7。

2个回答

29

我在github上问了redis-py的作者andymccurdy,他在答案中如下所述:

如果你使用的是redis-py<=2.9.1版本,则socket_timeout既是套接字连接的超时时间,也是读写套接字的超时时间。我最近推出了一项更改(465e74d),引入了一个新选项socket_connect_timeout。这允许你为socket.connect()和socket.send/socket.recv()指定不同的超时值。这个更改将包含在即将发布的2.10版本中。

redis-py版本是2.6.7,因此它既是套接字连接的超时时间,也是读写套接字的超时时间。


3

这取决于redis-py的版本。如果您使用的是redis-py<=2.9.1,则socket_timeout既是套接字连接的超时时间,也是读/写套接字的超时时间。 - hupantingxue

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接