Redis如何根据两个不同的排序集进行排序? [英] How can Redis sort according to two different sorted sets?

查看:464
本文介绍了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 result
  • k1 is the Sorted Set that stores the editor_id
  • k2 is the Sorted Set that stores the day
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆