the spring:session:expirations:${roundUpToNextMinute} redis SET is store value call keyToExpire:
String expireKey = getExpirationKey(toExpire);
BoundSetOperations<Object, Object> expireOperations = this.redis.boundSetOps(expireKey);
expireOperations.add(keyToExpire);
the keyToExpire is a string like expires:${sessionId}
https://github.com/spring-projects/spring-session/blob/927008bdc89701555f2f8f900f4f898df23b1476/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java#L97
however, when delete the session, it actually remove the session id not expires:${sessionId}
this.redis.boundSetOps(expireKey).remove(session.getId());
Is this a defact or My misunderstanding?
The behavior of session expiration handling for Redis session repository is described both in the RedisOperationsSessionRepository javadoc and reference manual.
Are you experiencing any particular issue here?
Thank you for reply, I know Spring Redis will create 3 key in redis.
spring:session:sessions:${sessionId}spring:session:sessions:expires:${sessionId}expires:${sessionId} to the nearest minute set, a redis SET, which key is spring:session:expirations:${roundUpToNextMinute} .when delete a session, the second key will be delete, right?
And I found that SET still tracking the expireKey. Then I dont understand why not just remove expires:${sessionId} in the third key.
And I see the code, notice that RedisSessionExpirationPolicy#onDelete methond remove the ${sessionId} instead of expires:${sessionId} from the redis SET. but ${sessionId} will never add to the SET.
https://github.com/spring-projects/spring-session/blob/085554f56b0ee7c96d45a49daa1c664db5fb1184/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java#L70
So I create this issue. I think it's ok to clean up this element in the set. By change this line to something like:
this.redis.boundSetOps(expireKey).remove("expires:" + session.getId());
My English is not very good, hope you can understand what I mean.
@vpavic please take a look
Thanks for the report @Alwayswithme.
I'm going to close this issue as a duplicate of gh-585.
Please follow gh-585 for updates.
Most helpful comment
Thank you for reply, I know Spring Redis will create 3 key in redis.
spring:session:sessions:${sessionId}spring:session:sessions:expires:${sessionId}expires:${sessionId}to the nearest minute set, a redis SET, which key isspring:session:expirations:${roundUpToNextMinute} .when delete a session, the second key will be delete, right?
https://github.com/spring-projects/spring-session/blob/085554f56b0ee7c96d45a49daa1c664db5fb1184/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java#L484
And I found that SET still tracking the expireKey. Then I dont understand why not just remove expires:${sessionId} in the third key.
And I see the code, notice that RedisSessionExpirationPolicy#onDelete methond remove the
${sessionId}instead ofexpires:${sessionId}from the redis SET. but${sessionId}will never add to the SET.https://github.com/spring-projects/spring-session/blob/085554f56b0ee7c96d45a49daa1c664db5fb1184/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java#L70
So I create this issue. I think it's ok to clean up this element in the set. By change this line to something like:
My English is not very good, hope you can understand what I mean.