Java Code Examples for redis.clients.jedis.Pipeline#discard()

The following examples show how to use redis.clients.jedis.Pipeline#discard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisUtil.java    From gameserver with Apache License 2.0 6 votes vote down vote up
/**
 * Pop a ready room from "room_ready_set_<N>".
 */
public static final Tuple popKeyFromZset(String zsetName) {
	Pipeline pipeline = JedisFactory.getJedis().pipelined();
	
	try {
		pipeline.watch(zsetName);
		Response<Set<Tuple>> results = pipeline.zrangeWithScores(zsetName, 0, 0);
		pipeline.multi();
		pipeline.zremrangeByRank(zsetName, 0, 0);
		pipeline.exec();
		pipeline.sync();
		
		Set<Tuple> values = results.get();
		if (values.size() > 0) {
			return values.iterator().next();
		}
	} catch (Exception e) {
		try {
			pipeline.discard();
		} catch (Exception e1) {
		}
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testDiscardInPipeline() {
  Pipeline pipeline = jedis.pipelined();
  pipeline.multi();
  pipeline.set("foo", "bar");
  Response<String> discard = pipeline.discard();
  Response<String> get = pipeline.get("foo");
  pipeline.sync();
  discard.get();
  get.get();
}
 
Example 3
Source File: PipeliningTest.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
@Test(expected = JedisDataException.class)
public void pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti() {
  Pipeline pipeline = jedis.pipelined();
  pipeline.discard();
}