Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit 3e01ab4

Browse files
committed
fix time command when connection-wide encoding is set (fixes #266)
1 parent 4b2d4ec commit 3e01ab4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

aioredis/commands/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def _split(s):
240240

241241

242242
def to_time(obj):
243-
return float(obj[0] + b'.' + obj[1].zfill(6))
243+
return int(obj[0]) + int(obj[1]) * 1e-6
244244

245245

246246
def to_tuples(value):

tests/server_commands_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ def test_time(redis):
273273
pytest.assert_almost_equal(int(res), int(time.time()), delta=10)
274274

275275

276+
@pytest.mark.run_loop
277+
def test_time_with_encoding(create_redis, server, loop):
278+
redis = yield from create_redis(server.tcp_address, loop=loop,
279+
encoding='utf-8')
280+
res = yield from redis.time()
281+
assert isinstance(res, float)
282+
pytest.assert_almost_equal(int(res), int(time.time()), delta=10)
283+
284+
276285
@pytest.mark.run_loop
277286
def test_slowlog_len(redis):
278287
res = yield from redis.slowlog_len()

0 commit comments

Comments
 (0)