Redis如何根据两个不同的排序集进行排序? [英] How can Redis sort according to two different sorted sets?
本文介绍了Redis如何根据两个不同的排序集进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个不同的排序集.
I have two different sorted sets.
一个用于编辑者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?
推荐答案
假定article_id
是您成员的值,并且editor_id
/day
是相应的有序集中的得分,并假设每个
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
说明:
-
t
是一个临时键,将保存结果 -
k1
是存储editor_id
的排序集
-
k2
是存储day
的排序集
- 权重100乘
editor_id
乘以100(即,将其右移两个位置) -
AGGREGATE SUM
的得分如下:editor_id
* 100 +day
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
注意:
- 您可以使用
ZUNIONSTORE
代替以获得相同的结果 - 权重100的使用假定
day
是2位数的值
- you can use
ZUNIONSTORE
instead for the same result - the use of weight 100 assumes that
day
is a 2-digit value
这篇关于Redis如何根据两个不同的排序集进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文