【问题标题】:How to get ttl along with the value for a key in redis/redisson如何获取 ttl 以及 redis/redisson 中键的值
【发布时间】:2018-04-04 18:52:33
【问题描述】:

我正在使用 redisson java client 在 Redis 中存储键和值。 示例如下

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

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

当我在 mapCahce 上做 get 时,有没有办法获得密钥的剩余 ttl?

【问题讨论】:

    标签: java redis redisson


    【解决方案1】:

    目前您可以使用RKeys 并查询您感兴趣的键来做到这一点

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

    如果有一个包装器可以同时公开键的值和 ttl 会很好

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 2020-03-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 2020-02-23
      相关资源
      最近更新 更多