使用Redis在Spring-Session上添加会话销毁事件

fykwrbwg  于 5个月前  发布在  Redis
关注(0)|答案(2)|浏览(59)

有人知道如何在Spring Session中使用Redis添加session destroy事件吗?,我读到正常的方法是不可能的。我想这样做,因为我需要在会话被销毁后做一些清理过程(超时或注销)。我真的很感激你的帮助,提前感谢伙计们。

13z8s7eq

13z8s7eq1#

如果配置了ApplicationEventPublisherRedisOperationsSessionRepository将发布org.springframework.session.events.SessionDestroyedEvent(或者更确切地说,它的子类SessionDeletedEventSessionExpiredEvent)。如果您使用@EnableRedisHttpSession配置支持,这将自动发生。
这些事件将依次转换为javax.servlet.http.HttpSessionEvent,然后转发给所有HttpSessionListener,假设它们在应用程序上下文中注册为bean。
有关更多详细信息,请参阅Spring Session参考手册的HttpSessionServer部分。

q3aa0525

q3aa05252#

对于** Spring Boot 3+**
将**@EnableRedisHttpSession更改为->@EnableRedisIndexedHttpSession,此更改将在RedisSessionRepository上配置RedisIndexedSessionRepository**。
通过使用这个RedisIndexedSessionRepository,你现在可以开始监听SessionCreatedEventSessionDeletedEventSessionDestroyedEventSessionExpiredEvent事件。
如需详细说明,请访问此处。如需收听会话事件,请访问此处。

相关问题