Fix Redis session expiration entry deletion
Closes gh-585
This commit is contained in:
committed by
Eleftheria Stein-Kousathana
parent
c93513f18f
commit
69285f2a9a
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2019 the original author or authors.
|
* Copyright 2014-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -50,6 +50,8 @@ final class RedisSessionExpirationPolicy {
|
|||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(RedisSessionExpirationPolicy.class);
|
private static final Log logger = LogFactory.getLog(RedisSessionExpirationPolicy.class);
|
||||||
|
|
||||||
|
private static final String SESSION_EXPIRES_PREFIX = "expires:";
|
||||||
|
|
||||||
private final RedisOperations<Object, Object> redis;
|
private final RedisOperations<Object, Object> redis;
|
||||||
|
|
||||||
private final Function<Long, String> lookupExpirationKey;
|
private final Function<Long, String> lookupExpirationKey;
|
||||||
@@ -67,11 +69,12 @@ final class RedisSessionExpirationPolicy {
|
|||||||
void onDelete(Session session) {
|
void onDelete(Session session) {
|
||||||
long toExpire = roundUpToNextMinute(expiresInMillis(session));
|
long toExpire = roundUpToNextMinute(expiresInMillis(session));
|
||||||
String expireKey = getExpirationKey(toExpire);
|
String expireKey = getExpirationKey(toExpire);
|
||||||
this.redis.boundSetOps(expireKey).remove(session.getId());
|
String entryToRemove = SESSION_EXPIRES_PREFIX + session.getId();
|
||||||
|
this.redis.boundSetOps(expireKey).remove(entryToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onExpirationUpdated(Long originalExpirationTimeInMilli, Session session) {
|
void onExpirationUpdated(Long originalExpirationTimeInMilli, Session session) {
|
||||||
String keyToExpire = "expires:" + session.getId();
|
String keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();
|
||||||
long toExpire = roundUpToNextMinute(expiresInMillis(session));
|
long toExpire = roundUpToNextMinute(expiresInMillis(session));
|
||||||
|
|
||||||
if (originalExpirationTimeInMilli != null) {
|
if (originalExpirationTimeInMilli != null) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2019 the original author or authors.
|
* Copyright 2014-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -164,4 +164,11 @@ class RedisSessionExpirationPolicyTests {
|
|||||||
verify(this.hashOperations).persist();
|
verify(this.hashOperations).persist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void onDeleteRemoveExpirationEntry() {
|
||||||
|
this.policy.onDelete(this.session);
|
||||||
|
|
||||||
|
verify(this.setOperations).remove("expires:" + this.session.getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user