Skip to content

Commit d87d259

Browse files
committed
Reverting the change for getex arguments
1 parent 5c8a60f commit d87d259

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

redis/commands/core.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4980,8 +4980,7 @@ def hgetdel(
49804980
def hgetex(
49814981
self,
49824982
name: KeyT,
4983-
key: Optional[str] = None,
4984-
keys: Optional[list] = None,
4983+
*keys: str,
49854984
ex: Optional[ExpiryT] = None,
49864985
px: Optional[ExpiryT] = None,
49874986
exat: Optional[AbsExpiryT] = None,
@@ -5009,7 +5008,7 @@ def hgetex(
50095008
Available since Redis 8.0
50105009
For more information see https://redis.io/commands/hgetex
50115010
"""
5012-
if key is None and not keys:
5011+
if not keys:
50135012
raise DataError("'hgetex' should have at least one key provided")
50145013

50155014
opset = {ex, px, exat, pxat}
@@ -5018,11 +5017,6 @@ def hgetex(
50185017
"``ex``, ``px``, ``exat``, ``pxat``, "
50195018
"and ``persist`` are mutually exclusive."
50205019
)
5021-
keys_to_request = []
5022-
if key is not None:
5023-
keys_to_request.append(key)
5024-
if keys:
5025-
keys_to_request.extend(keys)
50265020

50275021
exp_options: list[EncodableT] = extract_expire_flags(ex, px, exat, pxat)
50285022

@@ -5034,8 +5028,8 @@ def hgetex(
50345028
name,
50355029
*exp_options,
50365030
"FIELDS",
5037-
len(keys_to_request),
5038-
*keys_to_request,
5031+
len(keys),
5032+
*keys,
50395033
)
50405034

50415035
def hincrby(

tests/test_asyncio/test_hash.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ async def test_hgetex_no_expiration(r):
328328
"b", "foo", "bar", mapping={"1": 1, "2": 2, "3": "three", "4": b"four"}
329329
)
330330

331-
assert await r.hgetex("b", keys=["foo", "1", "4"]) == [b"bar", b"1", b"four"]
332-
assert await r.hgetex("b", "foo", keys=["1", "4"]) == [b"bar", b"1", b"four"]
331+
assert await r.hgetex("b", "foo", "1", "4") == [b"bar", b"1", b"four"]
333332
assert await r.hgetex("b", "foo") == [b"bar"]
334333
assert await r.httl("b", "foo", "1", "4") == [-1, -1, -1]
335334

@@ -343,7 +342,7 @@ async def test_hgetex_expiration_configs(r):
343342

344343
test_keys = ["foo", "1", "4"]
345344
# test get with multiple fields with expiration set through 'ex'
346-
assert await r.hgetex("test:hash", keys=test_keys, ex=10) == [
345+
assert await r.hgetex("test:hash", *test_keys, ex=10) == [
347346
b"bar",
348347
b"1",
349348
b"four",
@@ -353,15 +352,15 @@ async def test_hgetex_expiration_configs(r):
353352
assert pytest.approx(ttl) == 10
354353

355354
# test get with multiple fields removing expiration settings with 'persist'
356-
assert await r.hgetex("test:hash", "foo", keys=["1", "4"], persist=True) == [
355+
assert await r.hgetex("test:hash", *test_keys, persist=True) == [
357356
b"bar",
358357
b"1",
359358
b"four",
360359
]
361360
assert await r.httl("test:hash", *test_keys) == [-1, -1, -1]
362361

363362
# test get with multiple fields with expiration set through 'px'
364-
assert await r.hgetex("test:hash", keys=test_keys, px=6000) == [
363+
assert await r.hgetex("test:hash", *test_keys, px=6000) == [
365364
b"bar",
366365
b"1",
367366
b"four",
@@ -390,13 +389,13 @@ async def test_hgetex_validate_expired_fields_removed(r):
390389

391390
# test get multiple fields with expiration set
392391
# validate that expired fields are removed
393-
assert await r.hgetex("test:hash", keys=["foo", "1", "3"], ex=1) == [
392+
assert await r.hgetex("test:hash", "foo", "1", "3", ex=1) == [
394393
b"bar",
395394
b"1",
396395
b"three",
397396
]
398397
await asyncio.sleep(1.1)
399-
assert await r.hgetex("test:hash", "foo", keys=["1", "3"]) == [None, None, None]
398+
assert await r.hgetex("test:hash", "foo", "1", "3") == [None, None, None]
400399
assert await r.httl("test:hash", "foo", "1", "3") == [-2, -2, -2]
401400
assert await r.hgetex("test:hash", "4") == [b"four"]
402401

@@ -448,7 +447,7 @@ async def test_hsetex_expiration_ex_and_keepttl(r):
448447
for ttl in ttls:
449448
assert pytest.approx(ttl) == 10
450449

451-
assert await r.hgetex("test:hash", keys=test_keys) == [
450+
assert await r.hgetex("test:hash", *test_keys) == [
452451
b"bar",
453452
b"1",
454453
b"2",
@@ -475,7 +474,7 @@ async def test_hsetex_expiration_px(r):
475474
for ttl in ttls:
476475
assert pytest.approx(ttl) == 60
477476

478-
assert await r.hgetex("test:hash", keys=test_keys) == [b"bar", b"1", b"2"]
477+
assert await r.hgetex("test:hash", *test_keys) == [b"bar", b"1", b"2"]
479478

480479

481480
@skip_if_server_version_lt("7.9.0")
@@ -502,7 +501,7 @@ async def test_hsetex_expiration_pxat_and_fnx(r):
502501
assert ttls[0] <= 30
503502
assert ttls[1] == -2
504503

505-
assert await r.hgetex("test:hash", keys=["foo", "1", "new"]) == [b"bar", b"1", None]
504+
assert await r.hgetex("test:hash", "foo", "1", "new") == [b"bar", b"1", None]
506505
assert (
507506
await r.hsetex(
508507
"test:hash",
@@ -517,7 +516,7 @@ async def test_hsetex_expiration_pxat_and_fnx(r):
517516
ttls = await r.httl("test:hash", "foo", "new")
518517
for ttl in ttls:
519518
assert ttl <= 61
520-
assert await r.hgetex("test:hash", keys=["foo", "foo_new", "new"]) == [
519+
assert await r.hgetex("test:hash", "foo", "foo_new", "new") == [
521520
b"bar",
522521
b"bar1",
523522
b"ok",
@@ -548,7 +547,7 @@ async def test_hsetex_expiration_exat_and_fxx(r):
548547
assert 10 < ttls[0] <= 30
549548
assert ttls[1] == -2
550549

551-
assert await r.hgetex("test:hash", keys=["foo", "1", "new"]) == [b"bar", b"1", None]
550+
assert await r.hgetex("test:hash", "foo", "1", "new") == [b"bar", b"1", None]
552551
assert (
553552
await r.hsetex(
554553
"test:hash",
@@ -560,7 +559,7 @@ async def test_hsetex_expiration_exat_and_fxx(r):
560559
)
561560
== 1
562561
)
563-
assert await r.hgetex("test:hash", keys=["foo", "1"]) == [b"bar1", b"new_value"]
562+
assert await r.hgetex("test:hash", "foo", "1") == [b"bar1", b"new_value"]
564563

565564

566565
@skip_if_server_version_lt("7.9.0")

tests/test_hash.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ def test_hgetex_no_expiration(r):
393393
r.delete("test:hash")
394394
r.hset("b", "foo", "bar", mapping={"1": 1, "2": 2, "3": "three", "4": b"four"})
395395

396-
assert r.hgetex("b", keys=["foo", "1", "4"]) == [b"bar", b"1", b"four"]
397-
assert r.hgetex("b", "foo", keys=["1", "4"]) == [b"bar", b"1", b"four"]
398-
assert r.hgetex("b", "foo") == [b"bar"]
396+
assert r.hgetex("b", "foo", "1", "4") == [b"bar", b"1", b"four"]
399397
assert r.httl("b", "foo", "1", "4") == [-1, -1, -1]
400398

401399

@@ -406,21 +404,21 @@ def test_hgetex_expiration_configs(r):
406404
test_keys = ["foo", "1", "4"]
407405

408406
# test get with multiple fields with expiration set through 'ex'
409-
assert r.hgetex("test:hash", keys=test_keys, ex=10) == [b"bar", b"1", b"four"]
407+
assert r.hgetex("test:hash", *test_keys, ex=10) == [b"bar", b"1", b"four"]
410408
ttls = r.httl("test:hash", *test_keys)
411409
for ttl in ttls:
412410
assert pytest.approx(ttl) == 10
413411

414412
# test get with multiple fields removing expiration settings with 'persist'
415-
assert r.hgetex("test:hash", keys=test_keys, persist=True) == [
413+
assert r.hgetex("test:hash", *test_keys, persist=True) == [
416414
b"bar",
417415
b"1",
418416
b"four",
419417
]
420418
assert r.httl("test:hash", *test_keys) == [-1, -1, -1]
421419

422420
# test get with multiple fields with expiration set through 'px'
423-
assert r.hgetex("test:hash", keys=test_keys, px=6000) == [b"bar", b"1", b"four"]
421+
assert r.hgetex("test:hash", *test_keys, px=6000) == [b"bar", b"1", b"four"]
424422
ttls = r.httl("test:hash", *test_keys)
425423
for ttl in ttls:
426424
assert pytest.approx(ttl) == 6
@@ -444,17 +442,17 @@ def test_hgetex_validate_expired_fields_removed(r):
444442
test_keys = ["foo", "1", "3"]
445443
# test get multiple fields with expiration set
446444
# validate that expired fields are removed
447-
assert r.hgetex("test:hash", keys=test_keys, ex=1) == [b"bar", b"1", b"three"]
445+
assert r.hgetex("test:hash", *test_keys, ex=1) == [b"bar", b"1", b"three"]
448446
time.sleep(1.1)
449-
assert r.hgetex("test:hash", keys=test_keys) == [None, None, None]
447+
assert r.hgetex("test:hash", *test_keys) == [None, None, None]
450448
assert r.httl("test:hash", *test_keys) == [-2, -2, -2]
451449
assert r.hgetex("test:hash", "4") == [b"four"]
452450

453451

454452
@skip_if_server_version_lt("7.9.0")
455453
def test_hgetex_invalid_inputs(r):
456454
with pytest.raises(exceptions.DataError):
457-
r.hgetex("b", keys=["foo", "1", "3"], ex=10, persist=True)
455+
r.hgetex("b", "foo", "1", "3", ex=10, persist=True)
458456

459457
with pytest.raises(exceptions.DataError):
460458
r.hgetex("b", "foo", ex=10.0, persist=True)
@@ -497,7 +495,7 @@ def test_hsetex_expiration_ex_and_keepttl(r):
497495
for ttl in ttls:
498496
assert pytest.approx(ttl) == 10
499497

500-
assert r.hgetex("test:hash", keys=["foo", "1", "2", "i1", "i2"]) == [
498+
assert r.hgetex("test:hash", "foo", "1", "2", "i1", "i2") == [
501499
b"bar",
502500
b"1",
503501
b"2",
@@ -522,7 +520,7 @@ def test_hsetex_expiration_px(r):
522520
ttls = r.httl("test:hash", *test_keys)
523521
for ttl in ttls:
524522
assert pytest.approx(ttl) == 60
525-
assert r.hgetex("test:hash", keys=test_keys) == [b"bar", b"1", b"2"]
523+
assert r.hgetex("test:hash", *test_keys) == [b"bar", b"1", b"2"]
526524

527525

528526
@skip_if_server_version_lt("7.9.0")
@@ -546,7 +544,7 @@ def test_hsetex_expiration_pxat_and_fnx(r):
546544
assert ttls[0] <= 30
547545
assert ttls[1] == -2
548546

549-
assert r.hgetex("test:hash", keys=["foo", "1", "new"]) == [b"bar", b"1", None]
547+
assert r.hgetex("test:hash", "foo", "1", "new") == [b"bar", b"1", None]
550548
assert (
551549
r.hsetex(
552550
"test:hash",
@@ -561,7 +559,7 @@ def test_hsetex_expiration_pxat_and_fnx(r):
561559
ttls = r.httl("test:hash", "foo", "new")
562560
for ttl in ttls:
563561
assert ttl <= 61
564-
assert r.hgetex("test:hash", keys=["foo", "foo_new", "new"]) == [
562+
assert r.hgetex("test:hash", "foo", "foo_new", "new") == [
565563
b"bar",
566564
b"bar1",
567565
b"ok",
@@ -589,7 +587,7 @@ def test_hsetex_expiration_exat_and_fxx(r):
589587
assert 10 < ttls[0] <= 30
590588
assert ttls[1] == -2
591589

592-
assert r.hgetex("test:hash", keys=["foo", "1", "new"]) == [b"bar", b"1", None]
590+
assert r.hgetex("test:hash", "foo", "1", "new") == [b"bar", b"1", None]
593591
assert (
594592
r.hsetex(
595593
"test:hash",
@@ -601,7 +599,7 @@ def test_hsetex_expiration_exat_and_fxx(r):
601599
)
602600
== 1
603601
)
604-
assert r.hgetex("test:hash", keys=["foo", "1"]) == [b"bar1", b"new_value"]
602+
assert r.hgetex("test:hash", "foo", "1") == [b"bar1", b"new_value"]
605603

606604

607605
@skip_if_server_version_lt("7.9.0")

0 commit comments

Comments
 (0)