Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the redis timeout waiting for the response with pipeline in redis-py?

In the code below, is the pipeline timeout 2 seconds?

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()

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',)

If I modify the socket_timeout value to 10, it returns ok.
Doesn't the param "socket_timeout" mean connection timeout? But it looks like response timeout.
The redis-py version is 2.6.7.

like image 949
hupantingxue Avatar asked May 29 '14 09:05

hupantingxue


1 Answers

I asked andymccurdy , the author of redis-py, on github and the answer is as below:

If you're using redis-py<=2.9.1, socket_timeout is both the timeout for socket connection and the timeout for reading/writing to the socket. I pushed a change recently (465e74d) that introduces a new option, socket_connect_timeout. This allows you to specify different timeout values for socket.connect() differently from socket.send/socket.recv(). This change will be included in 2.10 which is set to be released later this week.

The redis-py version is 2.6.7, so it's both the timeout for socket connection and the timeout for reading/writing to the socket.

like image 184
hupantingxue Avatar answered Oct 11 '22 15:10

hupantingxue