18

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.

hupantingxue
  • 2,134
  • 3
  • 19
  • 24

2 Answers2

29

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.

Community
  • 1
  • 1
hupantingxue
  • 2,134
  • 3
  • 19
  • 24
3

It is not connection timeout, it is operation timeout. Internally the socket_timeout argument on StrictRedis() will be passed to the socket's settimeout method.

See here for details: https://docs.python.org/2/library/socket.html#socket.socket.settimeout

tobiash
  • 780
  • 6
  • 9
  • It depends on the version of redis-py.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. – hupantingxue Nov 26 '14 at 02:39