Junior — Middle
How can data relevance be ensured in Redis?
sobes.tech AI
Answer from AI
To ensure data freshness in Redis, the following methods can be used:
- Setting a Time To Live (TTL) for keys — allows automatic removal of outdated data.
- Publish/Subscribe (Pub/Sub) mechanisms — for notifying about changes and synchronizing data.
- Using Keyspace Notifications — enables reacting to key changes.
- Regularly updating data from the source — for example, periodic cache reset and overwrite.
- Using caching strategies with version or checksum verification — to update data only when changes occur.
Example of setting TTL in Java using Jedis:
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
jedis.expire("key", 3600); // key will expire in 3600 seconds