user1682076
user1682076

Reputation:

Redis With No TTL

Here is a snapshot of my redis settings

Total Keys  Keys with Expiry    Keys without Expiry
60Lacs      20Lacs              40Lacs  

Is there any method provided by Redis:

  1. Automatically set a TTL of 1 day on any key created by an application that doesn't specify a TTL

  2. Remove All existing keys with no TTL

Upvotes: 4

Views: 4490

Answers (1)

Tague Griffith
Tague Griffith

Reputation: 4173

As far as question one - No, Redis does not provide a global TTL setting. The TTL has to be set on a per key basis. There are some ways you could script a solution but there is nothing built in. If you are concerned about the memory usage, look in to your configurations and modify the max-memory settings. See this answer for more information.

As far as question two - This script in Python is a basic example of how to iterate over the keys and delete anything without a TTL, you should build on it for your needs. Important information about making this performant can be found in this answer.

import redis
r = redis.StrictRedis(host='localhost', port=6379)

for key in r.scan_iter("*"):
    ttl = r.ttl(key)
    if ttl == -1:
        r.delete(key)

Upvotes: 2

Related Questions