Skip to content

getex() edge cases allow exclusive options #3839

@x4204

Description

@x4204

There was an attempt at solving this in #1531, but it has some edge cases. For example:

>>> import redis
>>> r = redis.Redis()
>>> r.set('a', 'b')
True
>>> r.getex('a', ex=1000, px=1000)
b'b'
>>> r.ttl('a')
996

The call to getex() doesn't fail because extract_expire_flags() will use the first option that is not None.

It throws the exception only when the option values are unique:

>>> r.getex('a', ex=2, px=1000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".venv/lib/python3.12/site-packages/redis/commands/core.py", line 1879, in getex
    "``ex``, ``px``, ``exat``, ``pxat``, "
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
redis.exceptions.DataError: ``ex``, ``px``, ``exat``, ``pxat``, and ``persist`` are mutually exclusive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions