本文整理了Java中redis.clients.jedis.Transaction.setex()
方法的一些代码示例,展示了Transaction.setex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.setex()
方法的具体详情如下:
包路径:redis.clients.jedis.Transaction
类名称:Transaction
方法名:setex
暂无
代码示例来源: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: mindwind/craft-atom
private void setex0(String key, int seconds, String value) {
t.setex(key, seconds, value);
}
代码示例来源:origin: pivotalsoftware/session-managers
@Override
public void set(String key, String sessionsKey, byte[] session, int timeout) throws UnsupportedEncodingException {
try(Jedis jedis = this.jedisPool.getResource()) {
Transaction t = jedis.multi();
t.setex(key.getBytes(Protocol.CHARSET), timeout, session);
t.sadd(sessionsKey, key);
t.exec();
}
}
代码示例来源:origin: io.digdag/digdag-standards
@Override
public void commit()
{
if (connection != null) {
if (!msetTarget.isEmpty()) {
Transaction multi = connection.multi();
for (Map.Entry<String, String> entry : msetTarget.entrySet()) {
multi.setex(entry.getKey(), DEFAULT_TTL, entry.getValue());
}
multi.exec();
}
msetTarget.clear();
// `connection` object is created for every time when ParamServerClientConnection
// is injected, and is not a singleton object.
// So we must close connection manually.
connection.close();
this.connection = null;
}
}
代码示例来源:origin: pivotalsoftware/session-managers
@Test
public void set() throws UnsupportedEncodingException {
byte[] session = "session".getBytes();
this.jedisNodeClient.set("key", SESSIONS_KEY, session, timeout);
verify(this.transaction, times(1)).setex("key".getBytes(Protocol.CHARSET), timeout, session);
verify(this.transaction, times(1)).sadd(SESSIONS_KEY,"key");
verify(this.transaction, times(1)).exec();
verify(this.jedis, times(1)).close();
}
代码示例来源:origin: ai.grakn/redisq
@Override
public void push(T document) {
long timestampMs = System.currentTimeMillis();
String serialized;
String stateSerialized;
try {
serialized = mapper.serialize(new TimedWrap<>(document, timestampMs));
stateSerialized = stateMapper.serialize(new StateInfo(NEW, timestampMs, ""));
} catch (SerializationException e) {
serializationErrors.mark();
throw new RedisqException("Could not serialize element " + document.getIdAsString(), e);
}
LOG.debug("Jedis active: {}, idle: {}", jedisPool.getNumActive(), jedisPool.getNumIdle());
try (Jedis jedis = jedisPool.getResource(); Timer.Context ignored = pushTimer.time();) {
Transaction transaction = jedis.multi();
String id = document.getIdAsString();
String lockId = names.lockKeyFromId(id);
transaction.setex(lockId, lockTime, "locked");
transaction.lpush(queueName, id);
transaction.setex(names.contentKeyFromId(id), ttlStateInfo, serialized);
transaction.setex(names.stateKeyFromId(id), ttlStateInfo, stateSerialized);
transaction.publish(names.stateChannelKeyFromId(id), stateSerialized);
transaction.exec();
LOG.debug("Pushed {} with lockTime {}s lock id: {}", id, lockTime, lockId);
}
}
代码示例来源:origin: com.intoverflow.booster/booster-core
@Override
public void put(Object key, Object value) {
redisContext.run(jedis -> {
byte[] keyBytes = toKeyBytes(key);
Transaction multi = jedis.multi();
long currentSeconds = System.currentTimeMillis() / 1000;
if (expireTime > 0) {
multi.setex(keyBytes, expireTime, serialize(value));
} else {
multi.set(keyBytes, serialize(value));
}
multi.zadd(keysetBytes, currentSeconds, keyBytes);
multi.exec();
});
}
代码示例来源:origin: apache/servicemix-bundles
@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: org.springframework.data/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);
}
}
内容来源于网络,如有侵权,请联系作者删除!