Skip to content

Commit

Permalink
Fix Redis session expiration entry deletion
Browse files Browse the repository at this point in the history
Closes gh-585
  • Loading branch information
swurzinger authored and eleftherias committed Mar 12, 2021
1 parent c93513f commit 69285f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,8 @@ final class RedisSessionExpirationPolicy {

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 Function<Long, String> lookupExpirationKey;
Expand All @@ -67,11 +69,12 @@ final class RedisSessionExpirationPolicy {
void onDelete(Session session) {
long toExpire = roundUpToNextMinute(expiresInMillis(session));
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) {
String keyToExpire = "expires:" + session.getId();
String keyToExpire = SESSION_EXPIRES_PREFIX + session.getId();
long toExpire = roundUpToNextMinute(expiresInMillis(session));

if (originalExpirationTimeInMilli != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -164,4 +164,11 @@ void onExpirationUpdatedPersistOnNegativeExpiration() {
verify(this.hashOperations).persist();
}

@Test
void onDeleteRemoveExpirationEntry() {
this.policy.onDelete(this.session);

verify(this.setOperations).remove("expires:" + this.session.getId());
}

}

0 comments on commit 69285f2

Please sign in to comment.