Using RedisTimeSeries downsampling to aggregate data

385 Views Asked by At

I want to use redis timeseries to store item count. i.e Monitoring many companies and Company A has an account where they have added employees... When an employee adds an item I want to update their count of today, thisweek and thismonth and also increment the company A's account items today, this week and this month. Is RedisTimeSeries the best technology and how can it be done to monitor multiple companies and their employees ?

1

There are 1 best solutions below

0
On

If you don't need the history of items over time, One option is to just use counters (integers, Redis Strings) in either a multi exec block or a Lua script.

I tagged the company name (A) so that all keys reside on the same shard. 123 denotes the employee id

MULTI
SADD {A}:123:items newItem
INCR {A}:123:total
INCR {A}:123:2021
INCR {A}:123:2021:month:07
INCR {A}:123:2021:week:32
EXEC

Alternatively, you could keep all the counts per user in a single hash and use HINCRBY

Either solution might need some clean up for longer running periods.