spring-session 2.0 实现细节

一、 前置知识

  1. redis 在键实际过期之后不一定会被删除,可能会继续存留

  2. 具有过期时间的 key 有两种方式来保证过期

一是这个键在过期的时候被访问了

二是后台运行一个定时任务自己删除过期的 key

划重点:这启发我们在 key 到期后只需要访问一下 key 就可以确保 redis 删除该过期键

二、三种类型的键

A型键(Hash):spring:session:sessions:2ce8e358-3c23-4233-af40-a338deb0691f
B型键(Set):spring:session:expirations:1550627520000
C型键(String):spring:session:sessions:expires:2ce8e358-3c23-4233-af40-a338deb0691f

A/B类型的键ttl比C的长5分钟

三、运行机制

  1. 定时任务每分钟查找spring:session:expirations:{timestamp}的值

参考github issue并发导致的问题

  1. B类型键的值

  2. RedisSessionExpirationPolicy.onExpirationUpdated

You will note that the expiration that is set is 5 minutes after the session
actually expires. This is necessary so that the value of the session can be
accessed when the session expires. An expiration is set on the session itself
five minutes after it actually expires to ensure it is cleaned up, but only
after we perform any necessary processing.

4.删除String类型键spring:session:sessions:expires触发键空间通知

Original: https://www.cnblogs.com/yuyutianxia/p/10318426.html
Author: 等风来。。
Title: spring-session 2.0 实现细节

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/541486/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球