Unlike typical RDBMS or MongoDB, Redis does not have a rich query language that you can use. In these stores, you accumulate raw data in the warehouse, and then you can use the query to calculate statistics. Redis is not adapted to this model.
With Redis, you need to calculate your statistics on the fly and store them directly instead of raw data.
For example, suppose we are only interested in statistics for several weeks, I would structure the data as follows:
because all criteria are discrete, simple hash objects can be used instead of zsets
one hash object per week
in each hash object, one counter per pair of sites, an event. Optionally, one counter per site and / or one counter per event.
So, when the event occurs, I would execute the following commands for Redis:
hincrby W32 site_A:event_A 1 hincrby W32 site_A:* 1 hincrby W32 *:event_A 1
Note: there is no need to initialize these counters. HINCRBY will create them (and the hash object) if they do not exist.
To get statistics for one week:
hgetall W32
In statistics, you have counters for each site / event, only for each site.
To get statistics for several weeks, run the following commands:
hgetall W32 hgetall W33 hgetall W34 hgetall W35 hgetall W36
and perform aggregation on the client side (quite simple if the language supports associative arrays, such as map, dictionary, etc.).
source share