问题
I have two different sorted sets.
One is for editor ID:
article_id editor_id
101 10
102 11
103 10
104 10
The other sorted set is for date sorting:
article_id day
101 29
102 27
103 25
104 27
I want to merge these sets which shows first editor second day sorted state. Which commands should I use?
回答1:
Assuming that article_id is your members' value and that editor_id/day are the scores in the respective Sorted Set, and assuming each article_id is present in both Sorted Sets, you can do the following:
ZINTERSTORE t 2 k1 k2 WEIGHTS 100 1 AGGREGATE SUM
Explanation:
tis a temporary key that will hold the resultk1is the Sorted Set that stores theeditor_idk2is the Sorted Set that stores theday- the weight 100 multiplies
editor_idby 100 (i.e. "shifts" it two places to the right) - the
AGGREGATE SUMresults in the following score:editor_id* 100 +day
Notes:
- you can use
ZUNIONSTOREinstead for the same result - the use of weight 100 assumes that
dayis a 2-digit value
来源:https://stackoverflow.com/questions/29281920/how-can-redis-sort-according-to-two-different-sorted-sets