I am trying to create a redis ordered set. The catch is the ordering need to be done based on two criteria, timestamp and score. But in redis, I can only provide one soring criteria:
ZADD {key} {timestamp} {value}
How to add score in this ordering as well plz?
Update: Here is the approach I have taken to merge the two different ordering factoring into a single float score value:
var score = Math.floor(result.created_time/(60*60*24*1000));
score = score + (result.matches/10);
Just to explain, I have first converted the timestamp to number of days. And my 'matches' value usually be 0-10. Thus, converted to a decimal value and added as fraction weight. Which giving me highest scored entries, sorted per day. Which is exactly what I needed.
Use decimals as scores in your Sorted Set - construct the score with the timestamp being the value on the left of the decimal point and the value on the right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With