About Redis expired key deletion Policy

there are three ways for Redis key to expire:

passive deletion: when reading / writing an expired key, a lazy delete policy is triggered to delete the expired key directly.

active deletion: since the lazy deletion policy cannot guarantee that cold data will be deleted in a timely manner, Redis will take the initiative to eliminate a batch of expired key on a regular basis.

active cleanup policy is triggered when the current used memory exceeds the maxmemory limit.

passive deletion is a little unclear, for example:

A set records which users participated in the activity. Set the expiration time of the key to one hour, assuming that the set now has 10 elements.
then when there are users participating in the critical point and ask for sadd data, redis will first check the validity of the current key, check it to be 0, delete the key, and then set the expiration time for one hour. At this time, the set has one element

. Is that how you understand

?

Oct.01,2021

be sure to delete and then sadd
otherwise the logic will be incorrect

Menu