本文整理了Java中redis.clients.jedis.Jedis.ttl()
方法的一些代码示例,展示了Jedis.ttl()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.ttl()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:ttl
[英]The TTL command returns the remaining time to live in seconds of a key that has an #expire(String,int) set. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset.
[中]TTL命令返回设置了#expire(字符串,int)的密钥的剩余生存时间(以秒为单位)。此自省功能允许Redis客户端检查给定密钥将在多少秒后继续作为数据集的一部分。
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.ttl(key);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.ttl(key);
}
}.run(key);
代码示例来源:origin: caoxinyu/RedisClient
protected boolean isPersist(String key) {
long ttl = jedis.ttl(key);
if(ttl > 0)
return false;
else
return true;
}
protected RedisVersion getRedisVersion(){
代码示例来源:origin: sohutv/cachecloud
@Override
public Long ttl(byte[] key) {
Jedis j = getShard(key);
return j.ttl(key);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long ttl(String key) {
Jedis j = getShard(key);
return j.ttl(key);
}
代码示例来源:origin: caoxinyu/RedisClient
@Override
protected void command() {
jedis.select(db);
second = jedis.ttl(key);
}
代码示例来源:origin: Netflix/conductor
@Override
public Long ttl(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.ttl(key);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: qiurunze123/miaosha
public String getLock(String key , int timeOut){
try {
Jedis jedis = RedisManager.getJedis();
String value = UUID.randomUUID().toString();
long end =System.currentTimeMillis()+timeOut;
while (System.currentTimeMillis()<end){
if(jedis.setnx(key,value) ==1){
jedis.expire(key, timeOut);
//锁设置成功 redis操作成功
return value;
}
if(jedis.ttl(key)== -1){
jedis.expire(key, timeOut);
}
Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: jfinal/jfinal
/**
* 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。
*/
public Long ttl(Object key) {
Jedis jedis = getJedis();
try {
return jedis.ttl(keyToBytes(key));
}
finally {close(jedis);}
}
代码示例来源:origin: mrdear/JavaWEB
@Override
public Long doWorkCallback(Jedis jedis) {
return jedis.ttl(key);
}
});
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Long ttl(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().ttl(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().ttl(key)));
return null;
}
return connection.getJedis().ttl(key);
} catch (Exception ex) {
throw connection.convertJedisAccessException(ex);
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Long ttl(byte[] key, TimeUnit timeUnit) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().ttl(key),
Converters.secondsToTimeUnit(timeUnit)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().ttl(key),
Converters.secondsToTimeUnit(timeUnit)));
return null;
}
return Converters.secondsToTimeUnit(connection.getJedis().ttl(key), timeUnit);
} catch (Exception ex) {
throw connection.convertJedisAccessException(ex);
}
}
代码示例来源:origin: jwpttcg66/NettyGameServer
/**
* 获取key的剩余时间
* @param key
* @return
*/
public long getKeyTTL(String key){
Jedis jedis = null;
long result = 0;
Set<String> keys = null;
boolean sucess = true;
try {
jedis = jedisPool.getResource();
result = jedis.ttl(key);
} catch (Exception e) {
sucess = false;
returnBrokenResource(jedis, "key ttl", e);
} finally {
if (sucess && jedis != null) {
returnResource(jedis);
}
}
return result;
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Long execute(Jedis connection) {
return connection.ttl(key);
}
}.runBinary(key);
代码示例来源:origin: binarywang/WxJava
@Override
public boolean isAccessTokenExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.ttl(accessTokenKey) < 2;
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public boolean isTicketExpired(TicketType type) {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.ttl(this.getTicketRedisKey(type)) < 2;
}
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public Long ttl(String key) {
String command = "ttl";
return instrumented(command, () -> delegated.ttl(key));
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Long ttl(final byte[] key) {
Jedis j = getShard(key);
return j.ttl(key);
}
代码示例来源:origin: binarywang/WxJava
@Override
public boolean isAuthorizerAccessTokenExpired(String appId) {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.ttl(this.getKey(this.authorizerAccessTokenKey, appId)) < 2;
}
}
代码示例来源:origin: com.github.sogyf/goja-jfinal
/**
* 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。
*/
public Long ttl(Object key) {
Jedis jedis = getJedis();
try {
return jedis.ttl(keyToBytes(key));
}
finally {close(jedis);}
}
内容来源于网络,如有侵权,请联系作者删除!