If an item lacks a TTL setting and is not in use, it will persist in the storage indefinitely unless deleted.
Run this command to delete stale items inside redis-cli:
eval "for _,k in ipairs(redis.call('keys', '*')) do if redis.call('object', 'idletime', k) > {SECONDS} then redis.call('expire', k, 1) end end" 0Note: {SECONDS} adjusts the time that the object is being idle.
The provided Redis command is a Lua script that performs the following actions:
redis.call('keys', '*')lists all keys in the Redis databaseredis.call('object', 'idletime', k)for each key, it checks the idle time.- If found unused for a given timeframe, it deletes it from the storage.
- The end
0command indicates that the script doesn’t require any additional keys to be passed as arguments.
This script is useful for cleaning up inactive keys in a Redis database. It removes keys that haven’t been accessed for a specified duration, effectively managing memory usage.