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

问题描述 投票:0回答:2

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

redis spring-session
2个回答
2
投票
如果配置了

RedisOperationsSessionRepository

org.springframework.session.events.SessionDestroyedEvent
将发布
SessionDeletedEvent
(或者更准确地说,它的子类
SessionExpiredEvent
ApplicationEventPublisher
)。如果您使用
@EnableRedisHttpSession
配置支持,这将自动发生。

这些事件随后将被转换为

javax.servlet.http.HttpSessionEvent
,然后转发到所有
HttpSessionListener
,假设它们已作为 beans 在您的应用程序上下文中注册。

更多详情请参考 HttpSessionListener Spring Session 参考手册的部分。


0
投票

适用于 spring boot 3+

@EnableRedisHttpSession
更改为 --->
@EnableRedisIndexedHttpSession
。 此更改将在 RedisSessionRepository 上配置 RedisIndexedSessionRepository

通过使用此

RedisIndexedSessionRepository
,您现在可以开始收听
SessionCreatedEvent
SessionDeletedEvent
SessionDestroyedEvent
SessionExpiredEvent
事件。

欲了解详细说明,请访问this。 要收听会话活动,请访问this

© www.soinside.com 2019 - 2024. All rights reserved.