Description
Version: Redis server version 2.6.3, redis-py version 3.3.8
Platform: Python2.7 and Python3.7 on Linux (CentOS 7.9)
Description:
redis,setex() has its arguments ordered differently in python2 and python3, but documents show it should only be in one way.
Function declaration states def setex(self, time, name, value)
which is the correct order of arguments in python3, but in python2, this gives the error:
Traceback (most recent call last):
File "my_module.py", line 221, in <module>
sys.exit(run(jobid))
File "my_module.py", line 201, in run
redis.setex("SNAPSHOT_{}".format(jobid), expiry, SNAPSHOT_DIR)
File "/sww/tools/lib64/python2.7/redis/client.py", line 1384, in setex
return self.execute_command('SETEX', name, time, value)
File "/sww/tools/lib64/python2.7/redis/client.py", line 361, in execute_command
return self.parse_response(connection, command_name, **options)
File "/sww/tools/lib64/python2.7/redis/client.py", line 371, in parse_response
response = connection.read_response()
File "/sww/tools/lib64/python2.7/redis/connection.py", line 311, in read_response
raise response
redis.exceptions.ResponseError: value is not an integer or out of range
To reproduce
Simple program that works in Python3 but fails in Python2:
import redis as _redis
redis._redis(host=HOST, port=PORT, db=0)
expiry = timedelta(days=7)
redis.setex("MY_KEY", expiry, "/var/log/my_value_to_store")
The change of order in redis.setex()
from name, value, time
to name, time, value
fixes the problem:
OLD (not working in python2): redis.setex("MY_KEY", expiry, "/var/log/my_value_to_store")
NEW (works in python2): redis.setex("MY_KEY", "/var/log/my_value_to_store", expiry)
As you see, I swapped the time and value argument placements, which now works in python2.7.
Expected behavior
Expected behaviour should either be that the documents would show it being different in python2, but is showing this: https://redis-py.readthedocs.io/en/stable/index.html#redis.Redis.setex
Additional information
I stumbled upon this when trying to make my script backward compatible, I now have to check if the script is running in python2.7 or python3.7 and then swap arguments around accordingly.