直接使用lua脚本实现即可,其他的数据结果思路也一样。
public void setNoClearExpire(String key, String value) { String script = "local t = redis.call('pttl', KEYS[1]);" + "redis.call('set', KEYS[1], ARGV[1]);" + "if (t > 0) then " + "redis.call('pexpire', KEYS[1], t); end;"; RScript rscript = redissonClient.getScript(); rscript.eval(RScript.Mode.READ_WRITE, script, RScript.ReturnType.BOOLEAN, Collections.singletonList(key), value); }