Skip to content

NameError: name 'hiredis' is not defined due to hiredis version being lower than 3 #3393

Closed
@helissonomc

Description

@helissonomc

Version: 5.1.0

Platform: Python 3.12 / ubuntu 22.04

Description: I started to get the error
output.append(hiredis.pack_command(args)) NameError: name 'hiredis' is not defined

I Believe the reason for this issue is because of the code inside redis/utils.py

try:
    import hiredis  # noqa

    # Only support Hiredis >= 3.0:
    HIREDIS_AVAILABLE = int(hiredis.__version__.split(".")[0]) >= 3
    HIREDIS_PACK_AVAILABLE = hasattr(hiredis, "pack_command")
except ImportError:
    HIREDIS_AVAILABLE = False
    HIREDIS_PACK_AVAILABLE = False

If the hiredis version is lower than 3 (which mine is) the HIREDIS_AVAILABLE is going to be false, therefore it will keep giving error inside the redis/connection.py file, because the import hiredis will not be executed, but the code still relies on this import.

I believe there should be a better error handling here warning people about this breaking change.

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