简体   繁体   中英

How to expire a HyperLogLog in Redis?

HyperLogLog s take up 12KB of space. I don't see anything in the docs about when that storage is freed up.

My current plan is to call EXPIRE every time I call PFADD , but I can't find much discussion about expiring HLLs, so I'm wondering if I'm doing it wrong...

I'm planning on using HLLs to count the number of active visitors on my site in real-time. I only want to keep the counts for the past hour around, freeing up anything older than that.

NO, you cannot expire items added to the HLL. Instead, EXPIRE command will expire the whole HLL.

In order to achieve your goal, you can create HLL for each hour, and expire the whole HLL after some time.

// for the 2019082200
PFADD user:2019082200 user1
// also set expiration for the HLL, and expire it after 10 hours
EXPIRE user:2019082200 36000

// add more users
PFADD user:2019082200 user2

// until the next hour, create a new HLL for the next hour
PFADD user:2019082201 user1
EXPIRE user:2019082201 36000

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