本文整理了Java中redis.clients.jedis.Jedis.setex()
方法的一些代码示例,展示了Jedis.setex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.setex()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:setex
[英]The command is exactly equivalent to the following group of commands: #set(String,String) + #expire(String,int). The operation is atomic.
Time complexity: O(1)
[中]该命令与以下命令组完全等效:#set(String,String)+#expire(String,int)。操作是原子的。
时间复杂度:O(1)
代码示例来源:origin: sohutv/cachecloud
@Override
public String execute(Jedis connection) {
return connection.setex(key, seconds, value);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public String execute(Jedis connection) {
return connection.setex(key, seconds, value);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
public String execute(Jedis connection) {
return connection.setex(keyByte, seconds, value);
}
}.runBinary(keyByte);
代码示例来源:origin: sohutv/cachecloud
@Override
public String setex(byte[] key, int seconds, byte[] value) {
Jedis j = getShard(key);
return j.setex(key, seconds, value);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public String setex(String key, int seconds, String value) {
Jedis j = getShard(key);
return j.setex(key, seconds, value);
}
代码示例来源:origin: shuzheng/zheng
/**
* 设置 String 过期时间
* @param key
* @param value
* @param seconds 以秒为单位
*/
public synchronized static void set(String key, String value, int seconds) {
try {
value = StringUtils.isBlank(value) ? "" : value;
Jedis jedis = getJedis();
jedis.setex(key, seconds, value);
jedis.close();
} catch (Exception e) {
LOGGER.error("Set keyex error : " + e);
}
}
代码示例来源:origin: qiujiayu/AutoLoadCache
@Override
public void setex(byte[] key, int seconds, byte[] value) {
Jedis jedis = shardedJedis.getShard(key);
jedis.setex(key, seconds, value);
}
代码示例来源:origin: liyiorg/weixin-popular
@Override
public boolean add(String key, int expire) {
Jedis jedis = null;
try {
jedis = pool.getResource();
jedis.setex(perfix + key, expire, DEFAULT_VALUE);
return true;
} catch (Exception e) {
logger.error("", e);
} finally {
if (jedis != null) {
jedis.close();
}
}
return false;
}
代码示例来源:origin: Netflix/conductor
@Override
public String setex(String key, int seconds, String value) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.setex(key, seconds, value);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: signalapp/Signal-Server
private void setBucket(String key, LeakyBucket bucket) {
try (Jedis jedis = cacheClient.getWriteResource()) {
String serialized = bucket.serialize(mapper);
jedis.setex(getBucketName(key), (int) Math.ceil((bucketSize / leakRatePerMillis) / 1000), serialized);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: qiurunze123/miaosha
/**
* 设置对象
* */
public <T> boolean set(KeyPrefix prefix, String key, T value) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
String str = beanToString(value);
if(str == null || str.length() <= 0) {
return false;
}
//生成真正的key
String realKey = prefix.getPrefix() + key;
int seconds = prefix.expireSeconds();
if(seconds <= 0) {
jedis.set(realKey, str);
}else {
jedis.setex(realKey, seconds, str);
}
return true;
}finally {
returnToPool(jedis);
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 存放 key value 对到 redis,并将 key 的生存时间设为 seconds (以秒为单位)。
* 如果 key 已经存在, SETEX 命令将覆写旧值。
*/
public String setex(Object key, int seconds, Object value) {
Jedis jedis = getJedis();
try {
return jedis.setex(keyToBytes(key), seconds, valueToBytes(value));
}
finally {close(jedis);}
}
代码示例来源:origin: signalapp/Signal-Server
private void persistQueue(ReplicatedJedisPool jedisPool, Key key) throws IOException {
Timer.Context timer = persistQueueTimer.time();
int messagesPersistedCount = 0;
try (Jedis jedis = jedisPool.getWriteResource()) {
while (true) {
jedis.setex(key.getUserMessageQueuePersistInProgress(), 30, "1".getBytes());
Set<Tuple> messages = jedis.zrangeWithScores(key.getUserMessageQueue(), 0, CHUNK_SIZE);
for (Tuple message : messages) {
persistMessage(key, (long)message.getScore(), message.getBinaryElement());
messagesPersistedCount++;
}
if (messages.size() < CHUNK_SIZE) {
jedis.del(key.getUserMessageQueuePersistInProgress());
return;
}
}
} finally {
timer.stop();
queueSizeHistogram.update(messagesPersistedCount);
}
}
代码示例来源:origin: mrdear/JavaWEB
@Override
public String doWorkCallback(Jedis jedis) {
return jedis.setex(key,seconds,value);
}
});
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Boolean setEx(byte[] key, long seconds, byte[] value) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(value, "Value must not be null!");
if (seconds > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Time must be less than Integer.MAX_VALUE for setEx in Jedis.");
}
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().setex(key, (int) seconds, value),
Converters.stringToBooleanConverter(), () -> false));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().setex(key, (int) seconds, value),
Converters.stringToBooleanConverter(), () -> false));
return null;
}
return Converters.stringToBoolean(connection.getJedis().setex(key, (int) seconds, value));
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: spinnaker/kayenta
@Scheduled(fixedDelayString = "#{@indexConfigurationProperties.heartbeatIntervalMS}")
public void heartbeat() {
try (Jedis jedis = jedisPool.getResource()) {
long timestamp = canaryConfigIndex.getRedisTime();
jedis.setex(HEARTBEAT_KEY_PREFIX + currentInstanceId, 15, timestamp + "");
}
}
代码示例来源:origin: pippo-java/pippo
@Override
public void save(SessionData sessionData) {
try (Jedis jedis = sessions.getResource()) {
jedis.setex(
sessionData.getId(),
idleTime,
transcoder.encode(sessionData));
}
}
代码示例来源:origin: javahongxi/whatsmars
public String setex(String key,int seconds,String value) {
Jedis jedis = fetchResource(false);
try {
return jedis.setex(key,seconds,value);
} finally {
if (jedis != null) {
jedis.close();
}
}
}
代码示例来源:origin: sanluan/PublicCMS
@Override
public void put(K key, V value, Integer expiryInSeconds) {
Jedis jedis = jedisPool.getResource();
if (null == expiryInSeconds) {
jedis.set(getKey(key), valueSerializer.serialize(value));
jedis.zadd(byteRegion, System.currentTimeMillis(), keySerializer.serialize(key));
} else {
jedis.setex(getKey(key), expiryInSeconds, valueSerializer.serialize(value));
}
jedis.close();
}
代码示例来源:origin: sanluan/PublicCMS
@Override
public void put(K key, V value, Integer expiryInSeconds) {
Jedis jedis = jedisPool.getResource();
if (null == expiryInSeconds) {
jedis.set(getKey(key), valueSerializer.serialize(value));
jedis.zadd(byteRegion, System.currentTimeMillis(), keySerializer.serialize(key));
} else {
jedis.setex(getKey(key), expiryInSeconds, valueSerializer.serialize(value));
}
jedis.close();
}
内容来源于网络,如有侵权,请联系作者删除!