diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java index cdbb52c9..799e9c64 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 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. @@ -42,13 +42,13 @@ import org.springframework.util.Assert; */ public class RedisSessionRepository implements SessionRepository { - private static final String DEFAULT_KEY_NAMESPACE = "spring:session:"; + private static final String DEFAULT_KEY_NAMESPACE = "spring:session"; private final RedisOperations sessionRedisOperations; private Duration defaultMaxInactiveInterval = Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); - private String keyNamespace = DEFAULT_KEY_NAMESPACE; + private String keyNamespace = DEFAULT_KEY_NAMESPACE + ":"; private FlushMode flushMode = FlushMode.ON_SAVE; @@ -76,12 +76,23 @@ public class RedisSessionRepository implements SessionRepository this.sessionRepository.setKeyNamespace(null)) .withMessage("keyNamespace must not be empty"); } + @Test + void setRedisKeyNamespace_NullNamespace_ShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(null)) + .withMessage("namespace must not be empty"); + } + @Test void setKeyNamespace_EmptyNamespace_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setKeyNamespace(" ")) .withMessage("keyNamespace must not be empty"); } + @Test + void setRedisKeyNamespace_EmptyNamespace_ShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(" ")) + .withMessage("namespace must not be empty"); + } + @Test void setFlushMode_ValidFlushMode_ShouldSetFlushMode() { this.sessionRepository.setFlushMode(FlushMode.IMMEDIATE); @@ -185,7 +203,7 @@ class RedisSessionRepositoryTests { @Test void save_NewSessionAndCustomKeyNamespace_ShouldSaveSession() { - this.sessionRepository.setKeyNamespace("custom:"); + this.sessionRepository.setRedisKeyNamespace("custom"); RedisSession session = this.sessionRepository.createSession(); this.sessionRepository.save(session); String key = "custom:sessions:" + session.getId();