cunla / fakeredis-py

Implementation of Redis API in python without having a server running. Fully compatible with using redis-py.
https://fakeredis.moransoftware.ca/
BSD 3-Clause "New" or "Revised" License
300 stars 49 forks source link

Support for floating point timeout values #289

Closed darintay closed 9 months ago

darintay commented 9 months ago

Describe the bug Floating point timeouts are unsupported in fakeredis, they are reported as negative values and error out. They are supported in real Redis.

From the Redis docs, e.g.: https://redis.io/commands/blpop/ The timeout argument is interpreted as a double value specifying the maximum number of seconds to block

To Reproduce

>>> import fakeredis
>>> r = fakeredis.FakeRedis()
>>> r.blpop("mylist1", 1.1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/redis/commands/core.py", line 2594, in blpop
    return self.execute_command("BLPOP", *keys)
  File "/usr/local/lib/python3.10/dist-packages/redis/client.py", line 536, in execute_command
    return conn.retry.call_with_retry(
  File "/usr/local/lib/python3.10/dist-packages/redis/retry.py", line 46, in call_with_retry
    return do()
  File "/usr/local/lib/python3.10/dist-packages/redis/client.py", line 537, in <lambda>
    lambda: self._send_command_parse_response(
  File "/usr/local/lib/python3.10/dist-packages/redis/client.py", line 513, in _send_command_parse_response
    return self.parse_response(conn, command_name, **options)
  File "/usr/local/lib/python3.10/dist-packages/redis/client.py", line 553, in parse_response
    response = connection.read_response()
  File "/home/ubuntu/.local/lib/python3.10/site-packages/fakeredis/_server.py", line 120, in read_response
    raise response
redis.exceptions.ResponseError: timeout is negative
>>> r.blpop("mylist1", 1)
>>> 

Expected behavior Floating point timeouts should work.

Additional context Thanks for making this great tool, super useful for tests!

cunla commented 9 months ago

Thanks for bringing this up. I will fix it during the weekend.