本文整理汇总了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();
}
}