Redis save does nothing if nothing has changed
Fixes gh-467
This commit is contained in:
@@ -771,6 +771,9 @@ public class RedisOperationsSessionRepository implements
|
||||
* session.
|
||||
*/
|
||||
private void saveDelta() {
|
||||
if (this.delta.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String sessionId = getId();
|
||||
getSessionBoundHashOperations(sessionId).putAll(this.delta);
|
||||
String principalSessionKey = getSessionAttrNameKey(
|
||||
@@ -781,7 +784,7 @@ public class RedisOperationsSessionRepository implements
|
||||
|| this.delta.containsKey(securityPrincipalSessionKey)) {
|
||||
if (this.originalPrincipalName != null) {
|
||||
String originalPrincipalRedisKey = getPrincipalKey(
|
||||
(String) this.originalPrincipalName);
|
||||
this.originalPrincipalName);
|
||||
RedisOperationsSessionRepository.this.sessionRedisOperations
|
||||
.boundSetOps(originalPrincipalRedisKey).remove(sessionId);
|
||||
}
|
||||
|
||||
@@ -166,6 +166,16 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
.isEqualTo(session.getCreationTime());
|
||||
}
|
||||
|
||||
// gh-467
|
||||
@Test
|
||||
public void saveSessionNothingChanged() {
|
||||
RedisSession session = this.redisRepository.new RedisSession(this.cached);
|
||||
|
||||
this.redisRepository.save(session);
|
||||
|
||||
verifyZeroInteractions(this.redisOperations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveJavadocSummary() {
|
||||
RedisSession session = this.redisRepository.createSession();
|
||||
@@ -202,6 +212,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
@Test
|
||||
public void saveJavadoc() {
|
||||
RedisSession session = this.redisRepository.new RedisSession(this.cached);
|
||||
session.setLastAccessedTime(session.getLastAccessedTime());
|
||||
|
||||
given(this.redisOperations.boundHashOps("spring:session:sessions:session-id"))
|
||||
.willReturn(this.boundHashOperations);
|
||||
|
||||
Reference in New Issue
Block a user