Skip to content

Cannot use IntEnum as ex value #3593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phi-friday opened this issue Apr 10, 2025 · 2 comments
Closed

Cannot use IntEnum as ex value #3593

phi-friday opened this issue Apr 10, 2025 · 2 comments

Comments

@phi-friday
Copy link

Describe the bug

Cannot use IntEnum as ex value.

To reproduce

from __future__ import annotations

import asyncio
from enum import IntEnum

from redis.asyncio import Redis


class SomeEnum(IntEnum):
    EX = 60


async def main() -> None:
    client = Redis.from_url("redis://localhost:6379/0")
    await client.set("key", "value", ex=SomeEnum.EX)


if __name__ == "__main__":
    asyncio.run(main())

output:

❯ uv run python ./test.py
Traceback (most recent call last):
  File "***/./test.py", line 19, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/home/phi/.local/share/uv/python/cpython-3.13.2-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/home/phi/.local/share/uv/python/cpython-3.13.2-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/phi/.local/share/uv/python/cpython-3.13.2-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "***/./test.py", line 15, in main
    await client.set("key", "value", ex=SomeEnum.EX)
  File "***/.venv/lib/python3.13/site-packages/redis/asyncio/client.py", line 616, in execute_command
    return await conn.retry.call_with_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "***/.venv/lib/python3.13/site-packages/redis/asyncio/retry.py", line 59, in call_with_retry
    return await do()
           ^^^^^^^^^^
  File "***/.venv/lib/python3.13/site-packages/redis/asyncio/client.py", line 590, in _send_command_parse_response
    return await self.parse_response(conn, command_name, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***/.venv/lib/python3.13/site-packages/redis/asyncio/client.py", line 637, in parse_response
    response = await connection.read_response()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***/.venv/lib/python3.13/site-packages/redis/asyncio/connection.py", line 577, in read_response
    raise response from None
redis.exceptions.ResponseError: value is not an integer or out of range

Expected behavior

IntEnum should also be available.

Additional information

❯ uv run python --version
Python 3.13.2
❯ uv pip list | grep redis
fakeredis                2.28.1
hiredis                  3.1.0
redis                    5.2.1
❯ docker ps -a | grep redis
34d11a926cc7   redis:7-bookworm   "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes   0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp   modest_wilson
❯ uname -r
5.15.167.4-microsoft-standard-WSL2
@petyaslavova
Copy link
Collaborator

Hi @phi-friday, it looks like you're trying to use the input without specifying a supported input type.
The ex parameter must be compatible with the following type hint: ExpiryT = Union[int, timedelta].
To fix this, simply set ex=SomeEnum.EX.value.

@phi-friday
Copy link
Author

Hi @phi-friday, it looks like you're trying to use the input without specifying a supported input type. The ex parameter must be compatible with the following type hint: ExpiryT = Union[int, timedelta]. To fix this, simply set ex=SomeEnum.EX.value.

An instance of IntEnum is an instance of int, so there is no problem with type hint, but I understand the decision not to support subclasses of int.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants