@@ -76,7 +76,7 @@ public RedisCache(String name, byte[] prefix, RedisOperations<? extends Object,
76
76
/**
77
77
* Return the value to which this cache maps the specified key, generically specifying a type that return value will
78
78
* be cast to.
79
- *
79
+ *
80
80
* @param key
81
81
* @param type
82
82
* @return
@@ -126,7 +126,7 @@ public <T> T get(final Object key, final Callable<T> valueLoader) {
126
126
127
127
/**
128
128
* Return the value to which this cache maps the specified key.
129
- *
129
+ *
130
130
* @param cacheKey the key whose associated value is to be returned via its binary representation.
131
131
* @return the {@link RedisCacheElement} stored at given key or {@literal null} if no value found for key.
132
132
* @since 1.5
@@ -162,7 +162,7 @@ public void put(final Object key, final Object value) {
162
162
* Add the element by adding {@link RedisCacheElement#get()} at {@link RedisCacheElement#getKeyBytes()}. If the cache
163
163
* previously contained a mapping for this {@link RedisCacheElement#getKeyBytes()}, the old value is replaced by
164
164
* {@link RedisCacheElement#get()}.
165
- *
165
+ *
166
166
* @param element must not be {@literal null}.
167
167
* @since 1.5
168
168
*/
@@ -188,7 +188,7 @@ public ValueWrapper putIfAbsent(Object key, final Object value) {
188
188
/**
189
189
* Add the element as long as no element exists at {@link RedisCacheElement#getKeyBytes()}. If a value is present for
190
190
* {@link RedisCacheElement#getKeyBytes()} this one is returned.
191
- *
191
+ *
192
192
* @param element must not be {@literal null}.
193
193
* @return
194
194
* @since 1.5
@@ -256,7 +256,7 @@ private ValueWrapper toWrapper(Object value) {
256
256
/**
257
257
* Metadata required to maintain {@link RedisCache}. Keeps track of additional data structures required for processing
258
258
* cache operations.
259
- *
259
+ *
260
260
* @author Christoph Strobl
261
261
* @since 1.5
262
262
*/
@@ -294,7 +294,7 @@ public boolean usesKeyPrefix() {
294
294
295
295
/**
296
296
* Get the binary representation of the key prefix.
297
- *
297
+ *
298
298
* @return never {@literal null}.
299
299
*/
300
300
public byte [] getKeyPrefix () {
@@ -303,7 +303,7 @@ public byte[] getKeyPrefix() {
303
303
304
304
/**
305
305
* Get the binary representation of the key identifying the data structure used to maintain known keys.
306
- *
306
+ *
307
307
* @return never {@literal null}.
308
308
*/
309
309
public byte [] getSetOfKnownKeysKey () {
@@ -312,7 +312,7 @@ public byte[] getSetOfKnownKeysKey() {
312
312
313
313
/**
314
314
* Get the binary representation of the key identifying the data structure used to lock the cache.
315
- *
315
+ *
316
316
* @return never {@literal null}.
317
317
*/
318
318
public byte [] getCacheLockKey () {
@@ -321,7 +321,7 @@ public byte[] getCacheLockKey() {
321
321
322
322
/**
323
323
* Get the name of the cache.
324
- *
324
+ *
325
325
* @return
326
326
*/
327
327
public String getCacheName () {
@@ -330,7 +330,7 @@ public String getCacheName() {
330
330
331
331
/**
332
332
* Set the default expiration time in seconds
333
- *
333
+ *
334
334
* @param defaultExpiration
335
335
*/
336
336
public void setDefaultExpiration (long seconds ) {
@@ -339,7 +339,7 @@ public void setDefaultExpiration(long seconds) {
339
339
340
340
/**
341
341
* Get the default expiration time in seconds.
342
- *
342
+ *
343
343
* @return
344
344
*/
345
345
public long getDefaultExpiration () {
@@ -721,26 +721,17 @@ public byte[] doInRedis(BinaryRedisCacheElement element, RedisConnection connect
721
721
722
722
waitForLock (connection );
723
723
724
- byte existingValue [] = null ;
725
-
726
- boolean keyMaintenance ;
727
-
728
724
byte [] keyBytes = element .getKeyBytes ();
729
725
byte [] value = element .get ();
730
726
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 );
736
729
}
737
730
738
- if (keyMaintenance ) {
739
- processKeyExpiration (element , connection );
740
- maintainKnownKeys (element , connection );
741
- }
731
+ maintainKnownKeys (element , connection );
732
+ processKeyExpiration (element , connection );
742
733
743
- return existingValue ;
734
+ return null ;
744
735
}
745
736
}
746
737
0 commit comments