(r)
| 335 | |
| 336 | @skip_if_server_version_lt("7.9.0") |
| 337 | async def test_hgetex_expiration_configs(r): |
| 338 | await r.delete("test:hash") |
| 339 | await r.hset( |
| 340 | "test:hash", "foo", "bar", mapping={"1": 1, "3": "three", "4": b"four"} |
| 341 | ) |
| 342 | |
| 343 | test_keys = ["foo", "1", "4"] |
| 344 | # test get with multiple fields with expiration set through 'ex' |
| 345 | assert await r.hgetex("test:hash", *test_keys, ex=10) == [ |
| 346 | b"bar", |
| 347 | b"1", |
| 348 | b"four", |
| 349 | ] |
| 350 | ttls = await r.httl("test:hash", *test_keys) |
| 351 | for ttl in ttls: |
| 352 | assert pytest.approx(ttl) == 10 |
| 353 | |
| 354 | # test get with multiple fields removing expiration settings with 'persist' |
| 355 | assert await r.hgetex("test:hash", *test_keys, persist=True) == [ |
| 356 | b"bar", |
| 357 | b"1", |
| 358 | b"four", |
| 359 | ] |
| 360 | assert await r.httl("test:hash", *test_keys) == [-1, -1, -1] |
| 361 | |
| 362 | # test get with multiple fields with expiration set through 'px' |
| 363 | assert await r.hgetex("test:hash", *test_keys, px=6000) == [ |
| 364 | b"bar", |
| 365 | b"1", |
| 366 | b"four", |
| 367 | ] |
| 368 | ttls = await r.httl("test:hash", *test_keys) |
| 369 | for ttl in ttls: |
| 370 | assert pytest.approx(ttl) == 6 |
| 371 | |
| 372 | # test get single field with expiration set through 'pxat' |
| 373 | expire_at = await redis_server_time(r) + timedelta(minutes=1) |
| 374 | assert await r.hgetex("test:hash", "foo", pxat=expire_at) == [b"bar"] |
| 375 | assert (await r.httl("test:hash", "foo"))[0] <= 61 |
| 376 | |
| 377 | # test get single field with expiration set through 'exat' |
| 378 | expire_at = await redis_server_time(r) + timedelta(seconds=10) |
| 379 | assert await r.hgetex("test:hash", "foo", exat=expire_at) == [b"bar"] |
| 380 | assert (await r.httl("test:hash", "foo"))[0] <= 10 |
| 381 | |
| 382 | |
| 383 | @skip_if_server_version_lt("7.9.0") |
nothing calls this directly
no test coverage detected