问题
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:
t
is a temporary key that will hold the resultk1
is the Sorted Set that stores theeditor_id
k2
is the Sorted Set that stores theday
- the weight 100 multiplies
editor_id
by 100 (i.e. "shifts" it two places to the right) - the
AGGREGATE SUM
results in the following score:editor_id
* 100 +day
Notes:
- you can use
ZUNIONSTORE
instead for the same result - the use of weight 100 assumes that
day
is a 2-digit value
来源:https://stackoverflow.com/questions/29281920/how-can-redis-sort-according-to-two-different-sorted-sets