Skip to content

Commit 301e65c

Browse files
vpaviceleftherias
authored andcommitted
Remove unnecessary Redis commands in RedisIndexedSessionRepository#save
See: #1331
1 parent 090a10f commit 301e65c

File tree

2 files changed

+3
-26
lines changed

2 files changed

+3
-26
lines changed

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.nio.charset.StandardCharsets;
2020
import java.util.Map;
21-
import java.util.Set;
2221
import java.util.UUID;
2322

2423
import org.junit.jupiter.api.BeforeEach;
@@ -135,22 +134,6 @@ void saves() throws InterruptedException {
135134
.isEqualTo(expectedAttributeValue);
136135
}
137136

138-
@Test
139-
void removeAttributeRemovedAttributeKey() {
140-
RedisSession toSave = this.repository.createSession();
141-
toSave.setAttribute("a", "b");
142-
this.repository.save(toSave);
143-
144-
toSave.removeAttribute("a");
145-
this.repository.save(toSave);
146-
147-
String id = toSave.getId();
148-
String key = "RedisIndexedSessionRepositoryITests:sessions:" + id;
149-
150-
Set<Map.Entry<Object, Object>> entries = this.redis.boundHashOps(key).entries().entrySet();
151-
assertThat(entries).extracting(Map.Entry::getKey).doesNotContain("sessionAttr:a");
152-
}
153-
154137
@Test
155138
void putAllOnSingleAttrDoesNotRemoveOld() {
156139
RedisSession toSave = this.repository.createSession();

spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -792,8 +792,7 @@ private void saveDelta() {
792792
return;
793793
}
794794
String sessionId = getId();
795-
BoundHashOperations<Object, Object, Object> boundHashOperations = getSessionBoundHashOperations(sessionId);
796-
boundHashOperations.putAll(this.delta);
795+
getSessionBoundHashOperations(sessionId).putAll(this.delta);
797796
String principalSessionKey = getSessionAttrNameKey(
798797
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME);
799798
String securityPrincipalSessionKey = getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);
@@ -812,11 +811,6 @@ private void saveDelta() {
812811
.add(sessionId);
813812
}
814813
}
815-
for (final Map.Entry<String, Object> attribute : this.delta.entrySet()) {
816-
if (attribute.getValue() == null) {
817-
boundHashOperations.delete(attribute.getKey());
818-
}
819-
}
820814

821815
this.delta = new HashMap<>(this.delta.size());
822816

0 commit comments

Comments
 (0)