Reputation: 11
I have SpringBoot app where microservices send and receive some data from redis stream. So, every service send record which is Map:
StringRedisTemplate redisTemplate = new StringRedisTemplate();
Map<String, String> recordMap = new HashMap<>();
recordMap.put("topic", "topicName");
recordMap.put("user", "John");
recordMap.put("somethingElse", "someData");
redisTemplate.opsForStream().add(
StreamRecords.newRecord()
.in("name_of_stream")
.ofMap(recordMap)))
Other services have
public class RedisMessagesListener implements StreamListener<String, MapRecord<String, String, String>>
which is triggered on each message in Redis, looks for "topic" value in record and do some staff.
The problem is that records, once sent to Redis Stream, are always stored by Redis.
I'm about to create @Scheduled method in Java ?
I need to delete old records of certain topics, left only N newest records (e.g., 1 000 000) ?.
How can I do that?
Upvotes: 0
Views: 1577
Reputation: 659
Redis XTRIM command is exactly meant for this sort of schedule jobs. [How to Xtrim (trim redis stream) in the safe way thread already have some solutions discussed
Upvotes: 1