有人知道如何使用 Redis 在 Spring Session 中添加会话销毁事件吗?,我读到正常的方法是不可能的。我想这样做,因为我需要在会话被销毁(超时或注销)后执行一些清理过程。 我非常感谢您的帮助,提前感谢大家。
RedisOperationsSessionRepository
,
org.springframework.session.events.SessionDestroyedEvent
将发布 SessionDeletedEvent
(或者更准确地说,它的子类 SessionExpiredEvent
和 ApplicationEventPublisher
)。如果您使用 @EnableRedisHttpSession
配置支持,这将自动发生。
这些事件随后将被转换为
javax.servlet.http.HttpSessionEvent
,然后转发到所有 HttpSessionListener
,假设它们已作为 beans 在您的应用程序上下文中注册。
更多详情请参考 HttpSessionListener Spring Session 参考手册的部分。
适用于 spring boot 3+
将
@EnableRedisHttpSession
更改为 --->@EnableRedisIndexedHttpSession
。
此更改将在 RedisSessionRepository 上配置 RedisIndexedSessionRepository 。
通过使用此
RedisIndexedSessionRepository
,您现在可以开始收听 SessionCreatedEvent
、SessionDeletedEvent
、SessionDestroyedEvent
和 SessionExpiredEvent
事件。