Home > other >  Is it possible to set Redis key expiration time when using Spring Integration RedisMessageStore
Is it possible to set Redis key expiration time when using Spring Integration RedisMessageStore

Time:01-25

Dears, I'd like to auto-expire Redis keys when using org.springframework.integration.redis.store.RedisMessageStore class in Spring Integration. I see some methods related to "expiry callback" but I could not find any documentation or examples yet. Any advice will be much appreciated.

@Bean
public MessageStore redisMessageStore(LettuceConnectionFactory redisConnectionFactory) {
   RedisMessageStore store = new RedisMessageStore(redisConnectionFactory, "TEST_");
   return store;
}

Spring Boot: 2.6.3, spring integration and spring-boot-starter-data-redis.

CodePudding user response:

The RedisMessageStore does not have any expiration features. And technically it must not. The point of this kind of store is too keep data until it is used. Look at it as persistent storage. The RedisMetadataStore is based on the RedisProperties object, so it also cannot use expiration feature for particular entry.

You probably talk about a MessageGroupStoreReaper, which really calls a MessageGroupStore.expireMessageGroups(long timeout), but that's already an artificial, cross-store implementation provided by the framework. The logic relies on the group.getTimestamp() and group.getLastModified(). So, still not that auto-expiration Redis feature.

The MessageGroupStoreReaper is a process needed to be run in your application: nothing Redis-specific.

See more info in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#reaper

  •  Tags:  
  • Related