Redis set default TTL to keys

1,570 views
Skip to first unread message

ann...@gmail.com

unread,
Dec 13, 2017, 6:08:12 AM12/13/17
to Redis DB
Hallo,

We have a requirement to set a time to live for all the redis cache keys that starts with a paticular namespace in our java spring application

Key format is "abc:xyz:12345.." and we would like to set a default TTL  on all the keys that start with  the namespace "abc". The namespace is programatically built.

Now from what I have read, the notion of setting a default TTL does not exist in Redis and we must set it for every key seperately.

But is there a place ( for example in the RedisTemplate or RedisCaheManger etc) where we could configure it so that every key is created with a default ttl instead of -1

We tried some approaches with Redis Cache Manager and Keyspace settings (  keyspaceSettings.setTimeToLive(long)) but were unsuccessful

Is it possible anyway using Redis Cache manager (like it is mentioned in this stackoverflow link : https://stackoverflow.com/questions/34893279/spring-data-redis-expire-key) to set a ttl for a set of keys with the setDefaultExpiration or setExpires method. 
Can it be used to set the TTL of all the keys generated or are they referring to setting the "cache" expiry and not the "key" expiry here.

Would greatly appreciate if any has tried to implement a default TTL or if you have an approach we could try out.

Thanks a lot!
Julie
Reply all
Reply to author
Forward
0 new messages