RedisCache.java get(...) method will return null in some cases [DATAREDIS-777]
See original GitHub issueSophist Wu opened DATAREDIS-777 and commented
org.springframework.data.redis.cache.RedisCache#get(org.springframework.data.redis.cache.RedisCacheKey)
public RedisCacheElement get(final RedisCacheKey cacheKey) {
Assert.notNull(cacheKey, "CacheKey must not be null!");
Boolean exists = (Boolean) redisOperations.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
return connection.exists(cacheKey.getKeyBytes());
}
});
if (!exists.booleanValue()) {
return null;
}
// The problem here is : What if the key expires, at this moments? The below return clause , will lookup in redis server for the key again, which would return null in the end.
return new RedisCacheElement(cacheKey, fromStoreValue(lookup(cacheKey)));
}
This problem doesn’t exist in 2.x and 1.7.x , but we don’t want upgrade to 2.x right now
Affects: 1.8.10 (Ingalls SR10)
Issue Links:
- DATAREDIS-673 RedisCache.get(…) returns false positive cache hit when key is deleted in-flight (“duplicates”)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
java - Can Make Redis server return NULL or False instead of ...
So what We do are when a client request API it first go to Redis to get data if there is no data...
Read more >Spring Data Redis
However, values can be null as long as the underlying serializer accepts them. Read the Javadoc of each serializer for more information. For ......
Read more >Spring Boot Redis: Ultimate Guide to Redis Cache with Spring ...
Here we see a few things: @CachePut is an annotation which does what it says. The return of a method is getting put...
Read more >Enhanced Mapping of Java Objects to Hashes
For Java objects mapped with SDR's @RedisHash annotation we enhance ... Then we'll use a CommandLineRunner @Bean annotated method to create ...
Read more >Spring Caching with Redis - Medium
So Redis can be used as a caching system or as a full-fledged database. ... On top of the GET method, we use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sophist Wu commented
I see what you changed in this version : to check from redis server , see if the corresponding value exist at redis server, if not , null will be returned (in 1.8.10 will return RedisCacheElement(cacheKey, fromStoreValue(null)).
Okay, many thanks, the logic seems correct, I will try if that works!
Sophist Wu commented
Thank you, Mark, It works now with 1.8.11 ! We can close this jira now