@@ -76,7 +76,7 @@ public RedisCache(String name, byte[] prefix, RedisOperations<? extends Object,
7676/** 
7777 * Return the value to which this cache maps the specified key, generically specifying a type that return value will 
7878 * be cast to. 
79-  *   
79+  * 
8080 * @param key 
8181 * @param type 
8282 * @return 
@@ -126,7 +126,7 @@ public <T> T get(final Object key, final Callable<T> valueLoader) {
126126
127127/** 
128128 * Return the value to which this cache maps the specified key. 
129-  *   
129+  * 
130130 * @param cacheKey the key whose associated value is to be returned via its binary representation. 
131131 * @return the {@link RedisCacheElement} stored at given key or {@literal null} if no value found for key. 
132132 * @since 1.5 
@@ -162,7 +162,7 @@ public void put(final Object key, final Object value) {
162162 * Add the element by adding {@link RedisCacheElement#get()} at {@link RedisCacheElement#getKeyBytes()}. If the cache 
163163 * previously contained a mapping for this {@link RedisCacheElement#getKeyBytes()}, the old value is replaced by 
164164 * {@link RedisCacheElement#get()}. 
165-  *   
165+  * 
166166 * @param element must not be {@literal null}. 
167167 * @since 1.5 
168168 */ 
@@ -188,7 +188,7 @@ public ValueWrapper putIfAbsent(Object key, final Object value) {
188188/** 
189189 * Add the element as long as no element exists at {@link RedisCacheElement#getKeyBytes()}. If a value is present for 
190190 * {@link RedisCacheElement#getKeyBytes()} this one is returned. 
191-  *   
191+  * 
192192 * @param element must not be {@literal null}. 
193193 * @return 
194194 * @since 1.5 
@@ -256,7 +256,7 @@ private ValueWrapper toWrapper(Object value) {
256256/** 
257257 * Metadata required to maintain {@link RedisCache}. Keeps track of additional data structures required for processing 
258258 * cache operations. 
259-  *   
259+  * 
260260 * @author Christoph Strobl 
261261 * @since 1.5 
262262 */ 
@@ -294,7 +294,7 @@ public boolean usesKeyPrefix() {
294294
295295/** 
296296 * Get the binary representation of the key prefix. 
297-  *   
297+  * 
298298 * @return never {@literal null}. 
299299 */ 
300300public  byte [] getKeyPrefix () {
@@ -303,7 +303,7 @@ public byte[] getKeyPrefix() {
303303
304304/** 
305305 * Get the binary representation of the key identifying the data structure used to maintain known keys. 
306-  *   
306+  * 
307307 * @return never {@literal null}. 
308308 */ 
309309public  byte [] getSetOfKnownKeysKey () {
@@ -312,7 +312,7 @@ public byte[] getSetOfKnownKeysKey() {
312312
313313/** 
314314 * Get the binary representation of the key identifying the data structure used to lock the cache. 
315-  *   
315+  * 
316316 * @return never {@literal null}. 
317317 */ 
318318public  byte [] getCacheLockKey () {
@@ -321,7 +321,7 @@ public byte[] getCacheLockKey() {
321321
322322/** 
323323 * Get the name of the cache. 
324-  *   
324+  * 
325325 * @return 
326326 */ 
327327public  String  getCacheName () {
@@ -330,7 +330,7 @@ public String getCacheName() {
330330
331331/** 
332332 * Set the default expiration time in seconds 
333-  *   
333+  * 
334334 * @param defaultExpiration 
335335 */ 
336336public  void  setDefaultExpiration (long  seconds ) {
@@ -339,7 +339,7 @@ public void setDefaultExpiration(long seconds) {
339339
340340/** 
341341 * Get the default expiration time in seconds. 
342-  *   
342+  * 
343343 * @return 
344344 */ 
345345public  long  getDefaultExpiration () {
@@ -721,26 +721,17 @@ public byte[] doInRedis(BinaryRedisCacheElement element, RedisConnection connect
721721
722722waitForLock (connection );
723723
724- byte  existingValue [] = null ;
725- 
726- boolean  keyMaintenance ;
727- 
728724byte [] keyBytes  = element .getKeyBytes ();
729725byte [] value  = element .get ();
730726
731- if  (connection .setNX (keyBytes , value )) {
732- keyMaintenance  = true ;
733- } else  {
734- existingValue  = connection .get (keyBytes );
735- keyMaintenance  = ObjectUtils .nullSafeEquals (value , existingValue );
727+ if  (!connection .setNX (keyBytes , value )) {
728+ return  connection .get (keyBytes );
736729}
737730
738- if  (keyMaintenance ) {
739- processKeyExpiration (element , connection );
740- maintainKnownKeys (element , connection );
741- }
731+ maintainKnownKeys (element , connection );
732+ processKeyExpiration (element , connection );
742733
743- return  existingValue ;
734+ return  null ;
744735}
745736}
746737
0 commit comments