A
A
Arkady2012-07-27 07:22:03
Redis
Arkady, 2012-07-27 07:22:03

How to organize data selection in Redis by date?

It is necessary to store the number of views by time interval, so that it would be possible to choose for: the last 24 hours, 30 days and half a year.
So far, there is one option: to do it according to the “users online” principle, but if you do, for example, an hourly interval (time() // 3600) for 30 days, you get ~ 720 keys per entity.
Maybe someone has already done this? What other options are there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Neutral, 2012-07-27
@Neutral

You can push all data on views into one value, each 4 bytes of which will contain the number of visits in one day - and work with them through GETBIT / SETBIT.

L
LuciferOverLondon, 2012-07-28
@LuciferOverLondon

the solution is simpler - sorted set
key - <name>_<date>_<hour>, value - number, added via zadd
in the case of setbit, locks will be needed, as far as I understand. with zadd -
old statistics are not needed, you can throw them into the database, for example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question