If you’re getting an error that reads “LIMIT is only supported in combination with either BYSCORE or BYLEX” it’s probably because you’re trying to use the LIMIT
clause without using the BYSCORE
or BYLEX
arguments.
This can happen when using the VRANGE
command without either of the BYSCORE
or BYLEX
arguments.
To fix this issue, use either the BYSCORE
or BYLEX
argument when using the command. This obviously means that we need to adjust our query so that it’s querying by score or lexicographically.
Example of Error
Here’s an example of code that causes the error:
ZRANGE scores 0 -1 LIMIT 1 3
Result:
(error) ERR syntax error, LIMIT is only supported in combination with either BYSCORE or BYLEX
I got the error because I didn’t include either BYSCORE
or BYLEX
in my code.
Solution
We can fix this problem by including either the BYSCORE
or BYLEX
argument:
ZRANGE scores -inf inf BYSCORE LIMIT 1 3
Result:
1) "user:1" 2) "user:3" 3) "user:5"
In my case, I changed the query around so that it’s querying by score. This is the score that is assigned to each element.