开发者

redis list items, TTL and ranking by score

开发者 https://www.devze.com 2023-04-06 21:59 出处:网络
I would like to sort blog articles by page hits over the past 5000 views. I was experimenting with the following (200, 205, 202 are id\'s of the blog articles):

I would like to sort blog articles by page hits over the past 5000 views.

I was experimenting with the following (200, 205, 202 are id's of the blog articles):

ZINCRBY blog_hits 1 200
ZINCRBY blog_hits 1 200
ZINCRBY blog_hits 1 200
ZINCRBY bl开发者_开发百科og_hits 1 205
ZINCRBY blog_hits 1 205
ZINCRBY blog_hits 1 202
ZRANGEBYSCORE blog_hits 0 9 WITHSCORES

Which will give me the top ten viewed pages. The only problem is the ZINCRBY doesn't seem to have a TTL or a way of ignoring increments that happen more than 5000 increments ago.

Is there a way I could use a list, add an entry of the blog id, then LTRIM the list and get a score? If this is the way could you please write a little example? If not, I'd be keen to see how I could best solve this problem.

Thanks, Mark


Try blog_hits_date, and then summarize the week

ZINCRBY "blog_hits_09_24_2011" 1 200
TTL "blog_hits_09_24_2011" 3600*24*7

Or move id with hits > 5000 to another list(*blog_hits_over_5000*).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号