From 4c2581d432bdbcf99f003042c62afa6868ba2884 Mon Sep 17 00:00:00 2001 From: marcoblos Date: Thu, 22 Sep 2016 15:54:27 -0300 Subject: [PATCH] Polish RedisSession Maintain standard using prefix inside the RedisSession to mathods call. Generalizing and methods. Fixes gh-638 --- .../RedisOperationsSessionRepository.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java b/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java index 0fdebc3b..aafaab98 100644 --- a/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java +++ b/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java @@ -684,7 +684,7 @@ public class RedisOperationsSessionRepository implements this.delta.put(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds()); this.delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime()); this.isNew = true; - flushImmediateIfNecessary(); + this.flushImmediateIfNecessary(); } /** @@ -705,8 +705,7 @@ public class RedisOperationsSessionRepository implements public void setLastAccessedTime(long lastAccessedTime) { this.cached.setLastAccessedTime(lastAccessedTime); - this.delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime()); - flushImmediateIfNecessary(); + this.putAndFlush(LAST_ACCESSED_ATTR, getLastAccessedTime()); } public boolean isExpired() { @@ -731,8 +730,7 @@ public class RedisOperationsSessionRepository implements public void setMaxInactiveIntervalInSeconds(int interval) { this.cached.setMaxInactiveIntervalInSeconds(interval); - this.delta.put(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds()); - flushImmediateIfNecessary(); + this.putAndFlush(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds()); } public int getMaxInactiveIntervalInSeconds() { @@ -749,14 +747,12 @@ public class RedisOperationsSessionRepository implements public void setAttribute(String attributeName, Object attributeValue) { this.cached.setAttribute(attributeName, attributeValue); - this.delta.put(getSessionAttrNameKey(attributeName), attributeValue); - flushImmediateIfNecessary(); + this.putAndFlush(getSessionAttrNameKey(attributeName), attributeValue); } public void removeAttribute(String attributeName) { this.cached.removeAttribute(attributeName); - this.delta.put(getSessionAttrNameKey(attributeName), null); - flushImmediateIfNecessary(); + this.putAndFlush(getSessionAttrNameKey(attributeName), null); } private void flushImmediateIfNecessary() { @@ -765,6 +761,11 @@ public class RedisOperationsSessionRepository implements } } + private void putAndFlush(String a, Object v) { + this.delta.put(a, v); + this.flushImmediateIfNecessary(); + } + /** * Saves any attributes that have been changed and updates the expiration of this * session.