本文整理了Java中redis.clients.jedis.Jedis.expire()
方法的一些代码示例,展示了Jedis.expire()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.expire()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:expire
[英]Set a timeout on the specified key. After the timeout the key will be automatically deleted by the server. A key with an associated timeout is said to be volatile in Redis terminology.
Volatile keys are stored on disk like the other keys, the timeout is persistent too like all the other aspects of the dataset. Saving a dataset containing expires and stopping the server does not stop the flow of time as Redis stores on disk the time when the key will no longer be available as Unix time, and not the remaining seconds.
Since Redis 2.1.3 you can update the value of the timeout of a key already having an expire set. It is also possible to undo the expire at all turning the key into a normal key using the #persist(String) command.
Time complexity: O(1)
[中]在指定的密钥上设置超时。超时后,服务器将自动删除密钥。在Redis术语中,具有相关超时的密钥称为易失性密钥。
易失性键像其他键一样存储在磁盘上,超时也像数据集的所有其他方面一样是持久的。保存包含expires的数据集并停止服务器不会停止时间流,因为Redis会在磁盘上存储密钥不再作为Unix时间可用的时间,而不是剩余的秒数。
由于Redis 2.1.3,您可以更新已设置过期的密钥的超时值。还可以使用#persist(String)命令将密钥转换为普通密钥,从而完全撤消过期。
时间复杂度:O(1)
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.expire(key, seconds);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.expire(key, seconds);
}
}.run(key);
代码示例来源:origin: yu199195/hmily
@Override
public Long expire(final String key, final int second) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.expire(key, second);
}
}
代码示例来源:origin: yu199195/Raincat
@Override
public Long expire(final String key, final int second) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.expire(key, second);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Long expire(final String key, final int second) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.expire(key, second);
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public boolean acquire(Jedis jedis) {
String value = jedis.get(lockKey);
if (value == null) {
boolean success = jedis.setnx(lockKey, lockValue) == 1;
if (success) {
jedis.expire(lockKey, expiredSeconds);
return true;
}
} else if (lockValue.equals(value)) {
jedis.expire(lockKey, expiredSeconds);
return true;
}
return false;
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public boolean acquire(Jedis jedis) {
String value = jedis.get(lockKey);
if (value == null) {
boolean success = jedis.setnx(lockKey, lockValue) == 1;
if (success) {
jedis.expire(lockKey, expiredSeconds);
return true;
}
} else if (lockValue.equals(value)) {
jedis.expire(lockKey, expiredSeconds);
return true;
}
return false;
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long expire(String key, int seconds) {
Jedis j = getShard(key);
return j.expire(key, seconds);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long expire(byte[] key, int seconds) {
Jedis j = getShard(key);
return j.expire(key, seconds);
}
代码示例来源:origin: yu199195/hmily
@Override
public Long expire(final String key, final int second) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.expire(key, second);
}
}
代码示例来源:origin: shuzheng/zheng
/**
* 设置 byte[] 过期时间
* @param key
* @param value
* @param seconds 以秒为单位
*/
public synchronized static void set(byte[] key, byte[] value, int seconds) {
try {
Jedis jedis = getJedis();
jedis.set(key, value);
jedis.expire(key, seconds);
jedis.close();
} catch (Exception e) {
LOGGER.error("Set key error : " + e);
}
}
代码示例来源:origin: apache/ignite
@Override public long expire(Jedis jedis, String key) {
return jedis.expire("k1", 2);
}
});
代码示例来源:origin: yu199195/Raincat
@Override
public Long expire(final String key, final int second) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.expire(key, second);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Long expire(final String key, final int second) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.expire(key, second);
}
}
代码示例来源:origin: shuzheng/zheng
/**
* sadd
* @param key
* @param value
* @param seconds
*/
public synchronized static void sadd(String key, String value, int seconds) {
try {
Jedis jedis = RedisUtil.getJedis();
jedis.sadd(key, value);
jedis.expire(key, seconds);
jedis.close();
} catch (Exception e) {
LOGGER.error("sadd error : " + e);
}
}
代码示例来源:origin: Netflix/conductor
@Override
public Long expire(String key, int seconds) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.expire(key, seconds);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: caoxinyu/RedisClient
@Override
protected void command() {
jedis.select(db);
if(second != -1)
jedis.expire(key, second);
else
jedis.persist(key);
}
代码示例来源:origin: jfinal/jfinal
/**
* 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。
* 在 Redis 中,带有生存时间的 key 被称为『易失的』(volatile)。
*/
public Long expire(Object key, int seconds) {
Jedis jedis = getJedis();
try {
return jedis.expire(keyToBytes(key), seconds);
}
finally {close(jedis);}
}
代码示例来源:origin: apache/incubator-dubbo
jedis.set(key, output.toByteArray());
if (expiry > 1000) {
jedis.expire(key, expiry / 1000);
代码示例来源:origin: apache/ignite
private void testExpire(Expiration exp) throws Exception {
try (Jedis jedis = pool.getResource()) {
jedis.set("k1", "v1");
Assert.assertTrue(jedis.exists("k1"));
Assert.assertEquals(1L, exp.expire(jedis, "k1"));
Assert.assertEquals("v1", jedis.get("k1"));
Thread.sleep(2100);
Assert.assertFalse(jedis.exists("k1"));
Assert.assertEquals(0L, (long)jedis.expire("k1", 2));
}
}
内容来源于网络,如有侵权,请联系作者删除!