Use ZRANGE REV for zrange(desc=True) on supported Redis versions
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 -1For the currently supported Redis versions, the expected command would be:
ZRANGE scores 0 -1 REVThis 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:
- Make
zrange(desc=True)sendZRANGE ... REVby default. - Add an explicit opt-in argument such as
force_zrange=Trueoruse_rev=True. - 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?
Source: redis/redis-py