Search code examples
redisstackexchange.redisnode-redisredis-clusterredislabs

redis expiry keys holding memory


We are expiring 1000 keys per sec by average while taking snapshot we happened to see the size of the dump is comparatively lesser than the primary since because the snapshot is excluding the expired key's memory. Since expiring keys holding much memory in our platform, is there any way that we can make redis to release the memory held for expired keys periodically. (we are using 2.8.21 engine) or latest redis engine versions will resolve this problem little efficiently. Please guide me to the correct platform if stackoverflow is not appropriate for my question.

Reclaim memory guide : https://docs.redislabs.com/latest/ri/memory-optimizations/reclaim-expired-keys-memory-faster/ ( but need suggestion, whether upgrading will help a lot or doing scan will be good as mentioned in the doc)


Solution

  • Expired keys are removed from memory:

    • Passively: when you try to access it and the key is found to be timed out. This is how doing a full SCAN would help you, it forces a passive removal across all the keyspace.
    • Actively: every 100 ms, it tries to remove from memory expired keys at random, never investing more than 1 ms per cycle at it, until it estimates that less than 25% of expired keys remain. The logic is not that trivial, see activeExpireCycle (2.8.21 version).

    Upgrading may help as there new features/configuration settings, like activedefrag.

    Please see Redis filling up memory fast, running --bigkeys free it up for solutions including eviction policy and active expiring frequency.