存储在 Spring (HTTP) Session 中的数据在销毁期间不会从 Redis 中删除 [英] Data stored in Spring (HTTP) Session is not removed from Redis during destroy

查看:49
本文介绍了存储在 Spring (HTTP) Session 中的数据在销毁期间不会从 Redis 中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新发布的 Spring Session 组件进行 PoC.这是由 Redis 存储库备份的,其中 Session 和存储在 session 中的对象/数据都被持久化.

i am doing a PoC with the newly released Spring Session component. This is backed-up by Redis repository, where both the Session and the objects/data stored in session are persisted to.

  1. 会话已在应用程序中创建
  2. 在 Redis CLI 中运行Keys *"命令并看到一个新条目(如spring:session:sessions:6b55103a-baf5-4a05-a127-3a9cfa15c164")
  3. 从应用程序中,向会话添加了一个自定义 bean
  4. 在 Redis CLI 中运行Keys *"命令,看到了另一个新条目这个 bean(比如 "\xac\xed\x00\x05t\x00\tcustomer1" ,因为bean 有一个值为customer1"的字符串)
  5. 我配置了 30 秒的自动过期时间,并在这段时间内未使用该应用程序
  6. sessionDestroyEvent 被触发并在实现 ApplicationListener 的监听器中被捕获
  7. 在 Redis CLI 中运行Keys *"命令,现在第一个创建会话条目消失了,但是自定义 bean 对象(customer1) 仍然留在 Redis 中

问题:

清理 Redis Store 是用户的责任吗?如果我有许多数据元素存储在我的会话中,我是否必须手动在会话销毁期间从 redis 存储中清除它们(注销和超时事件).

Is it the user responsibility to clean-up the Redis Store ? If i had many data elements stored in my session, should i have to manually clean them up from the redis store during session destroy (logout and timeout events).

更新:

当我发布这个问题并返回时(可能在 3/4 分钟后)到 Redis-CLI 列出密钥,现在我找不到 Customer1 对象.那么这是否意味着 Redis 会定期执行清理操作间隔,比如垃圾收集?

While i posted this question and went back (probably after 3/4 mins) to Redis-CLI to list the Keys, now i do not find the Customer1 object. So does that mean the clean-up is performed by Redis on some regular interval, like the Garbage collection ?

推荐答案

Session Expiration 部分 Spring Session 参考 详细描述了如何清理会话.

The Session Expiration section Spring Session reference describes in detail how sessions are cleaned up.

来自文档:

这种方法的一个问题是Redis不保证如果他们的键没有被触发,则何时会触发过期事件访问.具体是Redis用来清理的后台任务过期的密钥是低优先级任务,可能不会触发密钥到期.有关其他详细信息,请参阅过期事件的时间Redis 文档中的部分.

One problem with this approach is that Redis makes no guarantee of when the expired event will be fired if they key has not been accessed. Specifically the background task that Redis uses to clean up expired keys is a low priority task and may not trigger the key expiration. For additional details see Timing of expired events section in the Redis documentation.

...

出于这个原因,每个会话过期也会被跟踪到最近的分钟.这允许后台任务访问可能过期的会话,以确保 Redis 过期事件是以更确定的方式触发.

For this reason, each session expiration is also tracked to the nearest minute. This allows a background task to access the potentially expired sessions to ensure that Redis expired events are fired in a more deterministic fashion.

这篇关于存储在 Spring (HTTP) Session 中的数据在销毁期间不会从 Redis 中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆