【发布时间】:2014-06-25 16:05:05
【问题描述】:
我正在尝试找出一种方法,以便在 redis 中按类别有效地存储和检索文章的受欢迎程度。目前我正在考虑这样的解决方案。
创建一堆散列来跟踪文章在所有类别中的受欢迎程度,其中键是“全部”、年、月或周初,字段是文章 ID,值是计数器。为了更新一篇文章的受欢迎程度,我将使用 HINCRBY 来增加该文章的计数器
整体流行度的哈希值:
all: article_id <counter> // all time popular
2012: article_id <counter> // popular by year
2012-01: article_id <counter> // popular by month
2012-01-04: article_id <counter> // popular by week, where the date is the beginning of the week
并为每个类别创建一组哈希,例如下面是“category_1”的哈希
<category_1>:all: article_id <counter> // all time popular
<category_1>:2012: article_id <counter> // popular by year
<category_1>:2012-01: article_id <counter> // popular by month
<category_1>:2012-01-04: article_id <counter> // popular by week, where the date is the beginning of the week
'category_2' 的另一组
<category_2>:all: article_id <counter> // all time popular
<category_2>:2012: article_id <counter> // popular by year
<category_2>:2012-01: article_id <counter> // popular by month
<category_2>:2012-01-04: article_id <counter> // popular by week, where the date is the beginning of the week
所以每当一篇文章的受欢迎程度上升时,我都会增加两组哈希值,一组用于整体,另一组用于文章所属的类别。我还没有弄清楚如何检索最流行的文章(所有时间、每年等),甚至不确定是否可以使用“哈希”数据类型。
散列是正确的数据结构吗?关于如何为此建模解决方案的任何想法都会有所帮助。
【问题讨论】:
标签: redis