Answer the question
In order to leave comments, you need to log in
How to count the number of events per hour?
Hello!
The task is this: to count the number of events per hour in order to limit the number of calls to the API for a specific user.
I thought to shove a key into redis something like userId_eventName_time and set it to expire in one hour, and then get the number by getting the number according to the userId_eventName_* template. But this approach implies the creation of a huge number of keys and is hardly good.
Is there any other way to account for the number of events per hour?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
If the ultimate goal is to limit the amount, then it seems to me more economical in terms of resources to shift this work not to the application, but to the server, for example, using iptables It is done
something
like this wbtools.ru/?forum=22
can find.
The following solution is possible:
Create a table user_log (id, user_id, date) and add an entry to this table each time it is accessed.
Next, you pull the number of hits for a certain period of time:
SELECT COUNT(*)
FROM `user_log`
WHERE `date` >= '2016-01-24 18:00:00'
AND `date` < '2016-01-24 17:00:00'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question