Reputation: 1263
Now I hava about 100 million posts which is belong to many categories and Now I am trying to store the posts` view counts and download counts using redis.
But I have no idea about which data structure I should use to satisfy my request:
I want to get one user`s posts order by view count or download count
I want to get one category`s posts order by view count or download count
I think one data structure cannot satisfy my request.So what`s the best prictise?
thanks :)
Upvotes: 0
Views: 807
Reputation: 38989
I want to get one user`s posts order by view count or download count
You'll need two sorted sets per user. One for posts by views, one for posts by downloads.
I want to get one category`s posts order by view count or download count
Same thing. Keep two sorted sets per category. One for views, one for downloads.
That said, why do you need to use Redis for this? Is it absolutely necessary (read: do you need such high speed/throughput) to store all this information in memory in Redis? Consider storing this in a memory + disk datastore like Mongo and just using Redis to cache top results. Again, this depends entirely on your needs, but my guess is you don't really need to keep rarely accessed users or bottoms of categories in Redis. Memory's expensive.
Upvotes: 2