MCPcopy
hub / github.com/redis/redis-py / test_hgetex_expiration_configs

Function test_hgetex_expiration_configs

tests/test_hash.py:401–434  ·  view source on GitHub ↗
(r)

Source from the content-addressed store, hash-verified

399
400@skip_if_server_version_lt("7.9.0")
401def test_hgetex_expiration_configs(r):
402 r.delete("test:hash")
403 r.hset("test:hash", "foo", "bar", mapping={"1": 1, "3": "three", "4": b"four"})
404 test_keys = ["foo", "1", "4"]
405
406 # test get with multiple fields with expiration set through 'ex'
407 assert r.hgetex("test:hash", *test_keys, ex=10) == [b"bar", b"1", b"four"]
408 ttls = r.httl("test:hash", *test_keys)
409 for ttl in ttls:
410 assert pytest.approx(ttl) == 10
411
412 # test get with multiple fields removing expiration settings with 'persist'
413 assert r.hgetex("test:hash", *test_keys, persist=True) == [
414 b"bar",
415 b"1",
416 b"four",
417 ]
418 assert r.httl("test:hash", *test_keys) == [-1, -1, -1]
419
420 # test get with multiple fields with expiration set through 'px'
421 assert r.hgetex("test:hash", *test_keys, px=6000) == [b"bar", b"1", b"four"]
422 ttls = r.httl("test:hash", *test_keys)
423 for ttl in ttls:
424 assert pytest.approx(ttl) == 6
425
426 # test get single field with expiration set through 'pxat'
427 expire_at = redis_server_time(r) + timedelta(minutes=1)
428 assert r.hgetex("test:hash", "foo", pxat=expire_at) == [b"bar"]
429 assert r.httl("test:hash", "foo")[0] <= 61
430
431 # test get single field with expiration set through 'exat'
432 expire_at = redis_server_time(r) + timedelta(seconds=10)
433 assert r.hgetex("test:hash", "foo", exat=expire_at) == [b"bar"]
434 assert r.httl("test:hash", "foo")[0] <= 10
435
436
437@skip_if_server_version_lt("7.9.0")

Callers

nothing calls this directly

Calls 5

redis_server_timeFunction · 0.90
hsetMethod · 0.80
hgetexMethod · 0.80
httlMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected