Skip to content

Commit 69285f2

Browse files
swurzingereleftherias
authored andcommitted
Fix Redis session expiration entry deletion
Closes gh-585
1 parent c93513f commit 69285f2

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,8 @@ final class RedisSessionExpirationPolicy {
5050

5151
private static final Log logger = LogFactory.getLog(RedisSessionExpirationPolicy.class);
5252

53+
private static final String SESSION_EXPIRES_PREFIX = "expires:";
54+
5355
private final RedisOperations<Object, Object> redis;
5456

5557
private final Function<Long, String> lookupExpirationKey;
@@ -67,11 +69,12 @@ final class RedisSessionExpirationPolicy {
6769
void onDelete(Session session) {
6870
long toExpire = roundUpToNextMinute(expiresInMillis(session));
6971
String expireKey = getExpirationKey(toExpire);
70-
this.redis.boundSetOps(expireKey).remove(session.getId());
72+
String entryToRemove = SESSION_EXPIRES_PREFIX + session.getId();
73+
this.redis.boundSetOps(expireKey).remove(entryToRemove);
7174
}
7275

7376
void onExpirationUpdated(Long originalExpirationTimeInMilli, Session session) {
74-
String keyToExpire = "expires:" + session.getId();
77+
String keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();
7578
long toExpire = roundUpToNextMinute(expiresInMillis(session));
7679

7780
if (originalExpirationTimeInMilli != null) {

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -164,4 +164,11 @@ void onExpirationUpdatedPersistOnNegativeExpiration() {
164164
verify(this.hashOperations).persist();
165165
}
166166

167+
@Test
168+
void onDeleteRemoveExpirationEntry() {
169+
this.policy.onDelete(this.session);
170+
171+
verify(this.setOperations).remove("expires:" + this.session.getId());
172+
}
173+
167174
}

0 commit comments

Comments
 (0)