I usually set same ttl for millions of key. I found use-memroy don't obviously decrease, when the time came. When I use scan all key by scan command, use-memory slow decrease. Could you explain the condition? Is clean strategy slow? Thank you!
Comment From: 0xtonyxia
Redis uses lazy expiration strategy, keys that have already expired may not be deleted immediately. But if the key is accessed(using scan or other commands) and found expired, it will be deleted instantly and the related memory is also freed.
Link: https://redis.io/commands/expire
Comment From: linux2014linux
Oh, I got it.
Comment From: jorgeluis-perez
@0xtonyxia besides that the scan triggers the deletion of the expired keys, are the expired keys returned in the current scan iteration? I see to the effect of this deletion just in the next command that try to access those keys or the same scan command that find the expirations filter those keys from the response?