The idea is to move video views counters from inserting directly to the db to Redis using INC
/HINCRBY
, and, every x sec get a batch of them and insert in one go to the db. As I see it, there are 2 options:
- set key per id and
INC
- use hash and
HINCRBY
Both approaches have a disadvantage as I see it - there is no POP
/ atomic command to get and reset the views counter. Which makes me look at transaction of sort - pipeline or LUA for the GET
+ DEL
times the batch size..
Are those my only options? Is there a better option? What is the best practice?
BTW, maybe this is for a different topic, but I need same logic for date instead of counter (last active..), so it will be best to have one logic for both.