Let's say I have 5 entries in my Redis database:
news::id
: the ID of the last news;news::list
: a list of all news IDs;news:n
where n is the news ID: a hash containing fields such astitle
,url
, etc.;news:n:upvotes
: a list of all users' IDs who upvoted the news, thus giving the number of upvotes.news:n:downvotes
: a list of all users' IDs who downvoted the news, thus giving the number of downvotes.
Then I have multiple ranking algorithms, where rank =
:
upvotes_count
;upvotes_count - downvotes_count
;upvotes_count - downvotes_count - age
;upvotes_count / downvotes_count
;age
.
Now how do I sort those news according to each of these algorithms?
I thought about computing the different ranks on every votes, but then if I introduce a new algorithm I need to compute the new rank for all the news.
EVAL
could help but it won't be available until v2.6, which surely I don't want to wait for.
Eventually, I could retrieve all the news and put them in a Python list. But again it translates into a high memory usage, not to mention the fact that Redis stores its data in memory.
So is there a proper way to do this or should I just move to MongoDB?