Skip to content

Commit 0e19bc4

Browse files
committed
fix:support float timeout
1 parent a0576c4 commit 0e19bc4

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

fakeredis/_commands.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,6 @@ class BitValue(Int):
167167
MAX_VALUE = 1
168168

169169

170-
class Timeout(Int):
171-
"""Argument converter for timeouts"""
172-
173-
DECODE_ERROR = msgs.TIMEOUT_NEGATIVE_MSG
174-
MIN_VALUE = 0
175-
176-
177170
class Float(RedisType):
178171
"""Argument converter for floating-point values.
179172
@@ -231,6 +224,13 @@ def encode(cls, value: float, humanfriendly: bool) -> bytes:
231224
return "{:.17g}".format(value).encode()
232225

233226

227+
class Timeout(Float):
228+
"""Argument converter for timeouts"""
229+
230+
DECODE_ERROR = msgs.TIMEOUT_NEGATIVE_MSG
231+
MIN_VALUE = 0.0
232+
233+
234234
class SortFloat(Float):
235235
DECODE_ERROR = msgs.INVALID_SORT_FLOAT_MSG
236236

test/test_mixins/test_list_commands.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ def test_blpop_block(r: redis.Redis):
452452
thread.join()
453453

454454

455+
@pytest.mark.slow
456+
def test_blpop_block_float(r: redis.Redis):
457+
thread = _push_thread(r)
458+
try:
459+
assert testtools.raw_command(r, 'blpop', 'foo', 0) == [b'foo', b'value1']
460+
assert testtools.raw_command(r, 'blpop', 'foo', 1.1) == [b'foo', b'value2']
461+
finally:
462+
thread.join()
463+
464+
455465
@pytest.mark.slow
456466
def test_brpop_block(r: redis.Redis):
457467
thread = _push_thread(r)

0 commit comments

Comments
 (0)