本文整理匯總了Java中redis.clients.jedis.Transaction.lpush方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.lpush方法的具體用法?Java Transaction.lpush怎麽用?Java Transaction.lpush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Transaction
的用法示例。
在下文中一共展示了Transaction.lpush方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: add
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
public void add(String key, String value) {
if(fake) {
ConcurrentLinkedQueue<String> stack = circularStackMap.get(key);
if(stack==null) {
synchronized(circularStackMap) {
stack = circularStackMap.get(key);
if(stack==null) {
stack = new ConcurrentLinkedQueue<String>();
circularStackMap.put(key, stack);
}
}
}
stack.add(value);
while(stack.size() > capacity) {
stack.poll();
}
} else {
try(Jedis jedis = jedisPool.getResource()) {
Transaction transaction = jedis.multi();
transaction.lpush(key, value);
transaction.ltrim(key, 0, capacity); // right away trim to capacity so that we can pretend it is a circular list
transaction.expire(key, expireInSeconds); // don't keep the data forever
transaction.exec();
} catch (JedisException e) {
// make sure we can find back jedis related stuff in kibana
throw new IllegalStateException("problem connecting to jedis", e);
}
}
}
示例2: if_was_in_multi_but_exec_was_called_the_instance_can_be_used
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test public void if_was_in_multi_but_exec_was_called_the_instance_can_be_used() {
// GIVEN
Transaction tr = this.jedis.multi();
tr.lpush(KEY, VALUE);
tr.exec();
// WHEN
boolean result = this.jedis.exists(KEY);
// THEN
assertTrue(result);
}
示例3: emit
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public <P extends Serializable> void emit(final EventChannel<P> channel, final Event<P> event) {
Assertion.checkNotNull(channel);
Assertion.checkNotNull(event);
//----
try (final Jedis jedis = redisConnector.getResource()) {
final Transaction tx = jedis.multi();
final String base64Payload = encodeToBase64(event.getPayload());
tx.hset("event:" + event.getUuid(), "payload", base64Payload);
tx.lpush("events:" + channel + ":pending", "event:" + event.getUuid());
tx.exec();
}
}
示例4: emit
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Override
public void emit(final String channel, final Event event) {
Assertion.checkArgNotEmpty(channel);
Assertion.checkNotNull(event);
//----
try (final Jedis jedis = redisConnector.getResource()) {
final Transaction tx = jedis.multi();
tx.hset("event:" + event.getUuid(), "payload", event.getPayload());
tx.lpush("events:" + channel + ":pending", "event:" + event.getUuid());
tx.exec();
}
}