本文整理汇总了Java中redis.clients.jedis.ShardedJedisPipeline.expire方法的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedisPipeline.expire方法的具体用法?Java ShardedJedisPipeline.expire怎么用?Java ShardedJedisPipeline.expire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.ShardedJedisPipeline
的用法示例。
在下文中一共展示了ShardedJedisPipeline.expire方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hsetByte
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
/**
* 在hash中存入单个键值对
*
* @param key
* @param field
* @param value
* @param expireTime
*/
public void hsetByte(String key, String field, Object value, int expireTime) {
ShardedJedis shardedJedis = shardedJedisPool.getResource();
if (shardedJedis == null) {
return;
}
try {
ShardedJedisPipeline pipelined = shardedJedis.pipelined();
pipelined.hset(serializer.serialize(key), serializer.serialize(field),
serializer.serialize(value));
pipelined.expire(serializer.serialize(key), expireTime);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
shardedJedis.close();
}
}
示例2: setByNX
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@Override
public boolean setByNX(final String key, final String value, final int timeout) {
Assert.hasText(key);
Assert.hasText(value);
ShardedJedis jedis = null;
try {
jedis = POOL.getJedis(config.getRedisType());
final ShardedJedisPipeline pipeline = jedis.pipelined();
final Response<Long> set = pipeline.setnx(key, value);
final Response<Long> expire = pipeline.expire(key, timeout);
pipeline.sync();
return isSuccess(set.get()) && isSuccess(expire.get());
} catch (final Throwable e) {
throw new RedisClientException(e.getMessage(), e);
} finally {
POOL.close(jedis);
}
}
示例3: pAddSet
import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
public List<Object> pAddSet(String key, int seconds, String... values) {
try (ShardedJedis shardedJedis = shardedJedisPool.getResource()) {
ShardedJedisPipeline pipeline = shardedJedis.pipelined();
for(String value : values) {
pipeline.sadd(key, value);
}
pipeline.expire(key, seconds);
List<Object> result = pipeline.syncAndReturnAll();
result.remove(result.size() -1);
return result;
}
}