Answer the question
In order to leave comments, you need to log in
How to implement multiple sorting of data from radish?
There is a list of users, sorted by a certain numerical indicator. I store the whole thing in a sorted set in radish (score: this numeric value, value: userId). In total, by querying zrevrange from O to O + L-1 (where L is limit, O is offset), I get the data in descending order of the numeric parameter. Everything is great.
Now there is a need for secondary sorting by some other parameter (a user model is created by userId, where there is some other numerical parameter; if important, it is stored in a similar way in radish, it is obtained by the zrevrank request).
By secondary sorting I mean sorting like SQL ORDER BY field1, field2, ..., etc
.
Answer the question
In order to leave comments, you need to log in
The trick is that sortedsets are not sorted at the time of the data request. They are stored already sorted, and everything is sorted at the moment the data changes.
When we request data, redis already knows where it is.
As an option, somehow calculate the score in such a way that the records would already be sorted. But then for each set of fields to create on .
For field1, field2 -- one
For field1, field2, field3 -- another You
can also store multiple sorted sets for each field. And then "on the fly" combine them using ZUNIONSTORE / ZINTERSTORE and search already as a result of calculations.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question