简体   繁体   中英

Using RedisTimeSeries downsampling to aggregate data

I want to use redis timeseries to store item count. ie 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM