From e0cb2fb21745e903901bcbf8f6ded08015bdffd0 Mon Sep 17 00:00:00 2001 From: Stephen Kinser Date: Mon, 8 Apr 2024 17:05:58 -0600 Subject: [PATCH] Redis reads session once not twice during cleanup I noticed that the session gets read twice at https://github.com/spring-projects/spring-session/blob/4dc81ec10d0e2870bb6f208df924b2ab933a835e/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.java#L441-L442. This alters the code to only read it once. --- .../redis/ReactiveRedisIndexedSessionRepository.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.java index 4d4c4c230..0b3bdbb06 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.java @@ -385,13 +385,17 @@ private Mono getSession(String sessionId, boolean allowExpired) { @Override public Mono deleteById(String id) { + return internalDeleteById(id).then(); + } + + public Mono internalDeleteById(String id) { // @formatter:off return getSession(id, true) .flatMap((session) -> this.sessionRedisOperations.delete(getExpiredKey(session.getId())) .thenReturn(session)) .flatMap((session) -> this.sessionRedisOperations.delete(getSessionKey(session.getId())).thenReturn(session)) .flatMap((session) -> this.indexer.delete(session.getId()).thenReturn(session)) - .flatMap((session) -> this.expirationStore.remove(session.getId())); + .flatMap((session) -> this.expirationStore.remove(session.getId()).thenReturn(session)); // @formatter:on } @@ -438,8 +442,7 @@ private Mono onKeyDestroyedMessage(ReactiveSubscription.Message getSession(sessionId, true)) - .flatMap((session) -> this.deleteById(session.getId()).thenReturn(session)) + .flatMap(this::internalDeleteById) .map((session) -> { if (message.getChannel().equals(this.sessionDeletedChannel)) { return new SessionDeletedEvent(this, session);