Since zrange “Lexicographical order is used for elements with equal score” how do I go around this issue?
For example:
zadd s 0 1
zadd s 0 2
zadd s 0 10
zadd s 0 3
zrange s 0 4
1) 1
2) 10
3) 2
4) 3
How do I make it sort like this (while ofc honor the score):
1) 1
2) 2
3) 3
4) 10
You cannot alter the lexicographic order.
However, you could store a value whose lexicographic order matches with numerical order. For instance instead of storing:
you could store:
The first letter is just a code to indicate the number of digits of the numerical value (A=1, B=2, etc …), so that numerical and lexicographic order is the same. The client application can easily add/remove this prefix at store/retrieve time.