Redis ZREVRANGEBYSCORE Replacement

Starting with Redis 6.2.0, the ZRANGE command added the REV, BYSCORE, BYLEX and LIMIT options. The addition of the first three options means that the ZRANGE command can now do what the ZREVRANGE, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZRANGEBYLEX and ZREVRANGEBYLEX commands can do.

As a result, those commands are now deprecated (as of Redis 6.2.0).

Therefore, we should no longer use the ZREVRANGEBYSCORE command. Instead, we should use the ZRANGE command with the REV and BYSCORE argument.

Example

Here’s an example of the replacement for the ZREVRANGEBYSCORE command:

ZRANGE scores 550 220 BYSCORE REV WITHSCORES

Result:

1) "user:4"
2) "550"
3) "user:5"
4) "440"
5) "user:3"
6) "330"
7) "user:1"
8) "220"

That has the exact same effect as using the (deprecated) ZREVRANGEBYSCORE command like this:

ZREVRANGEBYSCORE scores 550 220 WITHSCORES

Result:

1) "user:4"
2) "550"
3) "user:5"
4) "440"
5) "user:3"
6) "330"
7) "user:1"
8) "220"

So in summary, instead of using the ZREVRANGEBYSCORE command, use the ZRANGE command with the REV and BYSCORE option.