A question that has been tormenting for a couple of days.
There is an application that uses mysql to store information about users and nosql / redis to provide quick write / read information.
There are a lot of these procedures (read / write), so radishes have been chosen.
Part of the task is completely ported to redis. but there is a question on which I can not yet find a solution.
The application should show the number of people "online."
If you can update the online field with the current timestamp on the sql when prompted and then do where online & gt; timestamp-15m and show everything
how can I be in the key-value repository yet I can not understand.
there was an option to create a key that would change every 15 minutes. For example:
and write there +1 if the request was in these 15 minutes.
But this option is not acceptable, since when you move from 14 to 15 minutes the counter will show 0.
In general, the question is this. How to withdraw and save "online" people.
(PS: There is an option to write current seconds, and then in a descending cycle, read the last 900 (15 minutes) and read them, but it seems to me through the ass solution)
When a key is formed, the key online_20110602_13_1, where the user id is written, the key is created for 15 minutes.
Every minute is a new key.
When you need to get a list - the last 15 keys pass and merge. It turns out that some values are duplicated, but not critical.
Since the key is made on 15M, they are cleaned and there is always a maximum of 15 keys per number of online ones in the radish.
At the moment, I consider the solution acceptable. - m
thank - francesca
I solved the problem in the following way: I write down the radish (sadd) ID and put / prolonged the “delayed” task (memcacheq) to delete it (srem) after 15 minutes.
on hit - ZADD guys_online & lt; unix_timestamp & gt; & lt; user_id & gt;
get the number of guys online - ZCOUNT guys_online & lt; unix_timestamp-15 * 60 & gt; + inf
clean old records from time to time
- ZREMRANGEBYSCORE guys_online -inf (& lt; unix_timestamp-15 * 60 & gt;