Java Redisson: 延长 Redis Key 过期时间 - touch 方法
在 Redisson 中,可以使用 'touch' 方法来延长 Key 的过期时间。'touch' 方法会更新 Key 的过期时间并返回更新后的过期时间。
使用 RedissonClient 获取值后,可以通过以下方式延长 Key 的过期时间:
RedissonClient redissonClient = // 初始化 RedissonClient 对象
// 获取值
String key = 'myKey';
String value = redissonClient.getBucket(key).get();
// 延长 Key 的过期时间
long newTtl = redissonClient.getBucket(key).touch();
System.out.println('新的过期时间为:' + newTtl);
以上代码将获取 Key 对应的值,并通过 'touch' 方法延长 Key 的过期时间。'touch' 方法返回的是更新后的过期时间,可以通过打印输出来查看更新后的过期时间。
原文地址: https://www.cveoy.top/t/topic/nbhy 著作权归作者所有。请勿转载和采集!