Skip to content

Use ZRANGE REV for zrange(desc=True) on supported Redis versions #4268

Description

@sjquant

Version: redis-py 8.1.0, Redis 8.x
Platform: Python 3.14 on macOS/Linux

Description:

The current redis-py README states that redis-py >= 6.0.0 supports Redis 7.2 to current.

Redis 7.2+ supports ZRANGE ... REV, while ZREVRANGE is deprecated:

However, the rank-only reverse path in Redis.zrange() still delegates to zrevrange():

redis.zrange("scores", 0, -1, desc=True)

This sends the following command on the wire:

ZREVRANGE scores 0 -1

For the currently supported Redis versions, the expected command would be:

ZRANGE scores 0 -1 REV

This appears to be a follow-up to the compatibility fix in #1697, which restored support for Redis versions older than 6.2. Those versions are no longer listed in the current supported-version matrix.

Expected behavior:

Could the legacy fallback be reconsidered for the currently supported Redis versions?

Possible approaches:

  1. Make zrange(desc=True) send ZRANGE ... REV by default.
  2. Add an explicit opt-in argument such as force_zrange=True or use_rev=True.
  3. Deprecate the legacy fallback and remove it in a future major release.

The current workaround is:

redis.execute_command("ZRANGE", "scores", 0, -1, "REV")

Would a backward-compatible opt-in API be preferred, or is removing the fallback acceptable given the current support matrix?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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