0

I want to show three rankings: overall, last 30 days and last 7 days.

I decided to use redis although I've never worked with it before.

The overall rankings seem pretty easy:

Every time a user registers I create a new member to my collection and increase the counter every time he gets a new point.

Then I can get the rank with ZRANK

But how can I get the rank with the points the user got in the last 7 days?

Alexander Scholz
  • 2,100
  • 1
  • 20
  • 35

1 Answers1

1

I think I've got it (please provide criticism and ideas for improvement):

As Pieter Noordhuis wrote in this answer: https://groups.google.com/forum/#!topic/redis-db/0xh7tVQsi9Q

all I have to do is:

ZINCRBY day:2014-03-03 1 userID2
ZINCRBY day:2014-03-03 1 userID
ZINCRBY day:2014-03-04 1 userID

ZUNIONSTORE out 2 day:2014-03-03 posts:day:2014-03-04

ZRANGE out 0 -1 WITHSCORES

Result is:

1) "userID"
2) "2"
3) "userID2"
4) "1"
Alexander Scholz
  • 2,100
  • 1
  • 20
  • 35
  • 1
    Sounds good. I'd name the keys like this though: `d:20140303` etc. to save more space. – Agis Mar 05 '14 at 23:01
  • Well this is too slow. With 500 000 users it needs up to 1.4s to get the rank of 5 users – Alexander Scholz Mar 08 '14 at 13:18
  • You could shard the sets. – Agis Mar 08 '14 at 13:20
  • How is this possible with sorted sets? On the redis page they write: "The partitioning granuliary is the key, so it is not possible to shard a dataset with a single huge key like a very big sorted set." http://redis.io/topics/partitioning – Alexander Scholz Mar 08 '14 at 14:03
  • You might want to check out my recent post on a similar question [here](http://stackoverflow.com/questions/22375662/redis-fan-out-news-feeds-in-list-or-sorted-set/22377007#22377007) – Tw Bert Mar 16 '14 at 16:14
  • Also [this link](http://stackoverflow.com/questions/21865045/how-to-store-aggregated-catalog-tree-search-result-in-redis/22137476#22137476) might come in handy. – Tw Bert Mar 16 '14 at 16:17