本文整理匯總了Java中redis.clients.jedis.Jedis.ttl方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.ttl方法的具體用法?Java Jedis.ttl怎麽用?Java Jedis.ttl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.ttl方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ttl
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long ttl(String key) {
log.trace("get set expire " + key);
Jedis jedis = null;
try {
jedis = redisConnection.getJedis();
jedis.select(dbIndex);
return jedis.ttl(key);
} catch (Exception e) {
log.warn(e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.close();
}
}
return -2L;
}
示例2: getKeyTTL
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 獲取key的剩餘時間
*
* @param key
* @return
*/
public long getKeyTTL(String key) {
Jedis jedis = null;
long ret = 0;
// Set<String> keys = null;
boolean success = true;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.ttl(key);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "key ttl", e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例3: ttl
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public long ttl(String key) {
Jedis jedis = jedisPool.getResource();
Long result = null;
try {
result = jedis.ttl(key);
} catch (Exception e) {
jedisPool.returnBrokenResource(jedis);
} finally {
jedisPool.returnResource(jedis);
}
return result;
}
示例4: getExpireSeconds
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* 獲取key的剩餘過期時間,單位:秒
*
* @param key key
* @return Long
*/
public Long getExpireSeconds(String key) {
Jedis jedis = null;
try {
jedis = getConnect();
return jedis.ttl(key.getBytes());
} catch (Exception e) {
logger.error("redis getRedisData data failed!", e);
return null;
} finally {
close(jedis);
}
}
示例5: ttl
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Long ttl(String key) {
Jedis jedis = jedisPool.getResource();
Long result = jedis.ttl(key);
jedis.close();
return result;
}
示例6: isKeyMatchAndAlive
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private boolean isKeyMatchAndAlive(Jedis jedis, String key, String value) {
long ttl = jedis.ttl(key);
if (ttl < 0) {
return false;
}
String valueInRedis = jedis.get(key);
if (valueInRedis == null || !valueInRedis.equals(value)) {
return false;
}
return true;
}
示例7: lockQueue
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private boolean lockQueue(String queueID) {
if (locked.get() == null) {
synchronized (this) {
if (locked.get() == null) {
locked.set(new AtomicInteger(0));
}
}
}
if (locked.get().incrementAndGet() > 1) {
return true;
}
Jedis jedis = jedisPool.getResource();
try {
String redisLockKey = makeRedisLockKey(queueID);
long lockRequestTime = System.currentTimeMillis();
while (true) {
String result = jedis.set(redisLockKey, "lockTheQueue", "NX", "EX", 120);
if (StringUtils.isNotEmpty(result) && result.equalsIgnoreCase("OK")) {
return true;
}
if (lockRequestTime + lockWaitTimeStamp > System.currentTimeMillis()) {
locked.get().decrementAndGet();
return false;
}
long sleepTime = jedis.ttl(redisLockKey) * 1000 - 10;
if (sleepTime > lockRequestTime) {
return false;
}
if (sleepTime > 0) {
CommonUtil.sleep(sleepTime / 4);
}
}
} finally {
IOUtils.closeQuietly(jedis);
}
}
示例8: lockQueue
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private boolean lockQueue(String queueID) {
if (locked.get() == null) {
synchronized (this) {
if (locked.get() == null) {
locked.set(new AtomicInteger(0));
}
}
}
boolean ret = false;
@Cleanup Jedis jedis = jedisPool.getResource();
if (locked.get().incrementAndGet() > 1) {
return true;
}
String redisLockKey = makeRedisLockKey(queueID);
long lockRequestTime = System.currentTimeMillis();
while (true) {
String result = jedis.set(redisLockKey, "lockTheQueue", "NX", "EX", 120);
if (StringUtils.isNotEmpty(result) && result.equalsIgnoreCase("OK")) {
ret = true;
break;
}
if (lockRequestTime + lockWaitTimeStamp < System.currentTimeMillis()) {
locked.get().decrementAndGet();
break;
}
long sleepTime = jedis.ttl(redisLockKey) * 1000 - 10;
if (sleepTime > lockRequestTime) {
return false;
}
if (sleepTime > 0) {
CommonUtil.sleep(sleepTime);
}
}
return ret;
}
示例9: isKeyAlive
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private boolean isKeyAlive(Jedis jedis, String key) {
long ttl = jedis.ttl(key);
return (ttl > 0);
}