@Override public Long ttl(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().ttl(key); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
/** * 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live) * @param key * @return key不存在:返回-2 key存在但没有设置生存时间:返回-1 */ public long ttl(String key){ return jedisCluster.ttl(key); } /**
public Long ttl(String key) { return jedisCluster.ttl(key); }
@Override public Long ttl(byte[] bytes) { return cluster.ttl(bytes); }
public Long ttl(byte[] key) { return jedisCluster.ttl(key); }
/** * 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。 */ public Long ttl(Object key) { return jedisCluster.ttl(keyToBytes(key)); }
@Override public Long ttl(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().ttl(key); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public long ttl(final String key) { Assert.hasText(key); try { return cluster.ttl(key); } catch (final Throwable e) { throw new RedisClientException(e.getMessage(), e); } }
@Override public Long ttl(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().ttl(key); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
/** * 以秒为单位,返回给定 key 的剩余生存时间 * 不存在:-2 * 永久:-1 * 修改为: * 永久:0 * 不存在:-1 */ public Long ttl(Object key) { if (null == key) { return null; } long ttl = -2; if (cluster) { ttl = jedisCluster.ttl(serializeKey(key)); } else { ttl = jedisOperator.ttl(serializeKey(key)); } // 当 key 不存在时,返回 -2 。 if (ttl == -2) { return -1l; } // 当 key 存在但没有设置剩余生存时间时,返回 -1 if (ttl == -1) { return 0l; } return ttl; }