javaredisredisson

How to get ttl along with the value for a key in redis/redisson


I am storing a Key and value in Redis using redisson java client . Example as below

RMapCache<String, Integer> mapCache = redisson.getMapCache("test");

    // with ttl = 10 seconds
    Integer prevValue = mapCache.put("1", 10, 10, TimeUnit.SECONDS);

Is there a way I can get the remaining ttl for the key when I do a get on the mapCahce ?


Solution

  • Currently you can do that using RKeys and querying for the keys you are interested in

    RKeys rkeys = redissonClient.getKeys();
    long ttl = rkeys.remainTimeToLive(key);
    

    It would be nice although to have a wrapper that exposes both the value and the ttl of a key