diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java index 3b2e1801..9d769e23 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -149,8 +148,7 @@ public class ReactiveRedisOperationsSessionRepository implements String sessionKey = getSessionKey(id); return this.sessionRedisOperations.opsForHash().entries(sessionKey) - .collect( - Collectors.toMap(e -> e.getKey().toString(), Map.Entry::getValue)) + .collectMap(e -> e.getKey().toString(), Map.Entry::getValue) .filter(map -> !map.isEmpty()).map(new SessionMapper(id)) .filter(session -> !session.isExpired()).map(RedisSession::new) .switchIfEmpty(Mono.defer(() -> deleteById(id).then(Mono.empty()))); diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java index 134b73f5..11a1702f 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java @@ -305,13 +305,17 @@ public class ReactiveRedisOperationsSessionRepositoryTests { @SuppressWarnings("unchecked") public void getSessionFound() { given(this.redisOperations.opsForHash()).willReturn(this.hashOperations); - String attrName = "attrName"; + String attribute1 = "attribute1"; + String attribute2 = "attribute2"; MapSession expected = new MapSession("test"); expected.setLastAccessedTime(Instant.now().minusSeconds(60)); - expected.setAttribute(attrName, "attrValue"); + expected.setAttribute(attribute1, "test"); + expected.setAttribute(attribute2, null); Map map = map( - ReactiveRedisOperationsSessionRepository.ATTRIBUTE_PREFIX + attrName, - expected.getAttribute(attrName), + ReactiveRedisOperationsSessionRepository.ATTRIBUTE_PREFIX + attribute1, + expected.getAttribute(attribute1), + ReactiveRedisOperationsSessionRepository.ATTRIBUTE_PREFIX + attribute2, + expected.getAttribute(attribute2), ReactiveRedisOperationsSessionRepository.CREATION_TIME_KEY, expected.getCreationTime().toEpochMilli(), ReactiveRedisOperationsSessionRepository.MAX_INACTIVE_INTERVAL_KEY, @@ -330,8 +334,10 @@ public class ReactiveRedisOperationsSessionRepositoryTests { assertThat(session.getId()).isEqualTo(expected.getId()); assertThat(session.getAttributeNames()) .isEqualTo(expected.getAttributeNames()); - assertThat(session.getAttribute(attrName)) - .isEqualTo(expected.getAttribute(attrName)); + assertThat(session.getAttribute(attribute1)) + .isEqualTo(expected.getAttribute(attribute1)); + assertThat(session.getAttribute(attribute2)) + .isEqualTo(expected.getAttribute(attribute2)); assertThat(session.getCreationTime()).isEqualTo(expected.getCreationTime()); assertThat(session.getMaxInactiveInterval()) .isEqualTo(expected.getMaxInactiveInterval()); diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java index d903f6d3..e89fcce1 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisOperationsSessionRepositoryTests.java @@ -370,14 +370,18 @@ public class RedisOperationsSessionRepositoryTests { @Test public void getSessionFound() { - String attrName = "attrName"; + String attribute1 = "attribute1"; + String attribute2 = "attribute2"; MapSession expected = new MapSession(); expected.setLastAccessedTime(Instant.now().minusSeconds(60)); - expected.setAttribute(attrName, "attrValue"); + expected.setAttribute(attribute1, "test"); + expected.setAttribute(attribute2, null); given(this.redisOperations.boundHashOps(getKey(expected.getId()))) .willReturn(this.boundHashOperations); - Map map = map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), - expected.getAttribute(attrName), + Map map = map(RedisOperationsSessionRepository.getSessionAttrNameKey(attribute1), + expected.getAttribute(attribute1), + RedisOperationsSessionRepository.getSessionAttrNameKey(attribute2), + expected.getAttribute(attribute2), RedisOperationsSessionRepository.CREATION_TIME_ATTR, expected.getCreationTime().toEpochMilli(), RedisOperationsSessionRepository.MAX_INACTIVE_ATTR, @@ -389,8 +393,10 @@ public class RedisOperationsSessionRepositoryTests { RedisSession session = this.redisRepository.findById(expected.getId()); assertThat(session.getId()).isEqualTo(expected.getId()); assertThat(session.getAttributeNames()).isEqualTo(expected.getAttributeNames()); - assertThat(session.getAttribute(attrName)) - .isEqualTo(expected.getAttribute(attrName)); + assertThat(session.getAttribute(attribute1)) + .isEqualTo(expected.getAttribute(attribute1)); + assertThat(session.getAttribute(attribute2)) + .isEqualTo(expected.getAttribute(attribute2)); assertThat(session.getCreationTime()).isEqualTo(expected.getCreationTime()); assertThat(session.getMaxInactiveInterval()) .isEqualTo(expected.getMaxInactiveInterval());