0

I am using RedisCache.putIfAbsent operation of spring-data-redis-1.6.2.RELEASE.jar to set the element value atomically along with the ttl value.

This is how I generate the Cache Manager instance

public CacheManager dsyncCacheManager() {
    RedisCacheManager redisCacheManager = new RedisCacheManager( redisTemplate() );
    redisCacheManager.setDefaultExpiration(defaultExpireTimeSeconds);
    return redisCacheManager;
}

This is how I call the method

cache.putIfAbsent( key, value );

However, When I go and check the ttl of the given key in redis, the value returned is -1 and not the expected ttl I used.

mnille
  • 1,328
  • 4
  • 16
  • 20
Bhaarat
  • 119
  • 2
  • 10
  • 1
    There's already an issue [DATAREDIS-542](https://jira.spring.io/browse/DATAREDIS-542) open in the bug tracker. – Christoph Strobl Aug 29 '16 at 08:34
  • @christoph-strobl : thank you for the quick reply. When can we expect this to be fixed? – Bhaarat Aug 29 '16 at 08:36
  • we've recently checked the code and it seems the `EXPIRE` command is issued correctly. I saw you did not set a `keySerializer` which defaults to the jdk serializer producing keys like `\xac\xed\x00\x05t\x00\x0bcache-key-1`. Which Redis version do you use? As of Redis 2.8 the `TTL` command returns -2 when called on a key that does not exist. Maybe you could add a failing testcase to [DATAREDIS-542](https://jira.spring.io/browse/DATAREDIS-542). – Christoph Strobl Aug 31 '16 at 06:55
  • we are using spring-data-redis-1.6.2.RELEASE.jar. Redis version 2.8.19 – Bhaarat Aug 31 '16 at 10:51
  • 1
    Regarding keySerializer, are you saying key expiry for RedisCache.putIfAbsent() command will NOT work on default key serializer?? – Bhaarat Aug 31 '16 at 10:59
  • the `RedisSerializer` has no impact on the `EXIPIRE` command just on the key generated. it just happens sometimes that the CLI is used to check the `TTL`, and using `cache-key-1` instead of `\xac\xed\x00\x05t\x00\x0bcache-key-1` can be source of confusion. just wanted to check that. – Christoph Strobl Aug 31 '16 at 11:23

0 Answers0