当前位置: 首页>>代码示例>>Java>>正文


Java Pipeline.exec方法代码示例

本文整理汇总了Java中redis.clients.jedis.Pipeline.exec方法的典型用法代码示例。如果您正苦于以下问题:Java Pipeline.exec方法的具体用法?Java Pipeline.exec怎么用?Java Pipeline.exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.Pipeline的用法示例。


在下文中一共展示了Pipeline.exec方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pipelineWithTransaction

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void pipelineWithTransaction() {
  Jedis jedis = pool.getResource();
  try {
    Pipeline p = jedis.pipelined();
    p.multi();
    for (int i = 0; i < rowCount; i++) {
      String key = RandomStringUtils.randomAlphabetic(8);
      p.set(key, RandomStringUtils.randomNumeric(5));
      p.expire(key, 5 * 60);
    }
    p.exec();
    p.sync();
  } catch (Exception e) {
    pool.returnResource(jedis);
  }
}
 
开发者ID:nickevin,项目名称:Qihua,代码行数:17,代码来源:RedisTransactionTest.java

示例2: multiWithMassiveRequests

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void multiWithMassiveRequests() {
  Pipeline p = jedis.pipelined();
  p.multi();

  List<Response<?>> responseList = new ArrayList<Response<?>>();
  for (int i = 0; i < 100000; i++) {
    // any operation should be ok, but shouldn't forget about timeout
    responseList.add(p.setbit("test", 1, true));
  }

  Response<List<Object>> exec = p.exec();
  p.sync();

  // we don't need to check return value
  // if below codes run without throwing Exception, we're ok
  exec.get();

  for (Response<?> resp : responseList) {
    resp.get();
  }
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:23,代码来源:PipeliningTest.java

示例3: multiWithSync

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void multiWithSync() {
  jedis.set("foo", "314");
  jedis.set("bar", "foo");
  jedis.set("hello", "world");
  Pipeline p = jedis.pipelined();
  Response<String> r1 = p.get("bar");
  p.multi();
  Response<String> r2 = p.get("foo");
  p.exec();
  Response<String> r3 = p.get("hello");
  p.sync();

  // before multi
  assertEquals("foo", r1.get());
  // It should be readable whether exec's response was built or not
  assertEquals("314", r2.get());
  // after multi
  assertEquals("world", r3.get());
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:PipeliningTest.java

示例4: getLastKnownValues

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Map<ExternalId, Map<String, String>> getLastKnownValues(final List<ExternalId> securities) {
  Map<ExternalId, Map<String, String>> result = Maps.newHashMap();
  JedisPool jedisPool = _redisConnector.getJedisPool();
  Jedis jedis = jedisPool.getResource();
  Pipeline pipeline = jedis.pipelined();
  //start transaction
  pipeline.multi();
  for (ExternalId identifier : securities) {
    String redisKey = generateRedisKey(identifier.getScheme().getName(), identifier.getValue(), getNormalizationRuleSetId());
    pipeline.hgetAll(redisKey);
  }
  Response<List<Object>> response = pipeline.exec();
  pipeline.sync();
  
  final Iterator<ExternalId> allSecItr = securities.iterator();
  final Iterator<Object> responseItr = response.get().iterator();
  while (responseItr.hasNext() && allSecItr.hasNext()) {
    result.put(allSecItr.next(), filterBlackListedTicks((Map<String, String>) responseItr.next()));
  }
  jedisPool.returnResource(jedis);
  return result;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:RedisLKVSnapshotter.java

示例5: popKeyFromZset

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:28,代码来源:JedisUtil.java

示例6: multi

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void multi() {
  Pipeline p = jedis.pipelined();
  p.multi();
  Response<Long> r1 = p.hincrBy("a", "f1", -1);
  Response<Long> r2 = p.hincrBy("a", "f1", -2);
  Response<List<Object>> r3 = p.exec();
  List<Object> result = p.syncAndReturnAll();

  assertEquals(new Long(-1), r1.get());
  assertEquals(new Long(-3), r2.get());

  assertEquals(4, result.size());

  assertEquals("OK", result.get(0));
  assertEquals("QUEUED", result.get(1));
  assertEquals("QUEUED", result.get(2));

  // 4th result is a list with the results from the multi
  @SuppressWarnings("unchecked")
  List<Object> multiResult = (List<Object>) result.get(3);
  assertEquals(new Long(-1), multiResult.get(0));
  assertEquals(new Long(-3), multiResult.get(1));

  assertEquals(new Long(-1), r3.get().get(0));
  assertEquals(new Long(-3), r3.get().get(1));

}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:29,代码来源:PipeliningTest.java

示例7: testCloseableWithMulti

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testCloseableWithMulti() throws IOException {
  // we need to test with fresh instance of Jedis
  Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
  jedis2.auth("foobared");

  Pipeline pipeline = jedis2.pipelined();
  Response<String> retFuture1 = pipeline.set("a", "1");
  Response<String> retFuture2 = pipeline.set("b", "2");

  pipeline.multi();

  pipeline.set("a", "a");
  pipeline.set("b", "b");

  pipeline.close();

  try {
    pipeline.exec();
    fail("close should discard transaction");
  } catch (JedisDataException e) {
    assertTrue(e.getMessage().contains("EXEC without MULTI"));
    // pass
  }

  // it shouldn't meet any exception
  retFuture1.get();
  retFuture2.get();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:30,代码来源:PipeliningTest.java

示例8: testCombPipelineTrans

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void testCombPipelineTrans() {// 0.099秒
	Jedis jedis = new Jedis("120.25.241.144", 6379);
	jedis.auth("b840fc02d52404542994");

	long start = System.currentTimeMillis();
	Pipeline pipeline = jedis.pipelined();
	pipeline.multi();
	for (int i = 0; i < 1000; i++) {
		pipeline.set("n" + i, "n" + i);
		System.out.println(i);
	}
	pipeline.exec();
	pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	System.out.println("共花费:" + (end - start) / 1000.0 + "秒");

	jedis.disconnect();
	try {
		Closeables.close(jedis, true);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:24,代码来源:RedisExample.java

示例9: test4combPipelineTrans

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void test4combPipelineTrans() {
	long start = System.currentTimeMillis();
	Pipeline pipeline = jedis.pipelined();
	pipeline.multi();
	for (int i = 0; i < 100000; i++) {
		pipeline.set("" + i, "" + i);
	}
	pipeline.exec();
	List<Object> results = pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	System.out.println("Pipelined transaction: " + ((end - start) / 1000.0) + " seconds");
}
 
开发者ID:dreajay,项目名称:jcode,代码行数:14,代码来源:TestJedis.java

示例10: pipleWithTransation

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
private static void pipleWithTransation(Pipeline pipeline) {
    for (int i = 0; i < KEY_COUNT; i++) {
        pipeline.set("pipletransation" + i, i + "");
    }
    pipeline.exec();
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:7,代码来源:RedisEasyTest.java

示例11: pipelineExecShoudThrowJedisDataExceptionWhenNotInMulti

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test(expected = JedisDataException.class)
public void pipelineExecShoudThrowJedisDataExceptionWhenNotInMulti() {
  Pipeline pipeline = jedis.pipelined();
  pipeline.exec();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:6,代码来源:PipeliningTest.java

示例12: testPipelinedTransactionResponse

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testPipelinedTransactionResponse() {

  String key1 = "key1";
  String val1 = "val1";

  String key2 = "key2";
  String val2 = "val2";

  String key3 = "key3";
  String field1 = "field1";
  String field2 = "field2";
  String field3 = "field3";
  String field4 = "field4";

  String value1 = "value1";
  String value2 = "value2";
  String value3 = "value3";
  String value4 = "value4";

  Map<String, String> hashMap = new HashMap<String, String>();
  hashMap.put(field1, value1);
  hashMap.put(field2, value2);

  String key4 = "key4";
  Map<String, String> hashMap1 = new HashMap<String, String>();
  hashMap1.put(field3, value3);
  hashMap1.put(field4, value4);

  jedis.set(key1, val1);
  jedis.set(key2, val2);
  jedis.hmset(key3, hashMap);
  jedis.hmset(key4, hashMap1);

  Pipeline pipeline = jedis.pipelined();
  pipeline.multi();

  pipeline.get(key1);
  pipeline.hgetAll(key2);
  pipeline.hgetAll(key3);
  pipeline.get(key4);

  Response<List<Object>> response = pipeline.exec();
  pipeline.sync();

  List<Object> result = response.get();

  assertEquals(4, result.size());

  assertEquals("val1", result.get(0));

  assertTrue(result.get(1) instanceof JedisDataException);

  Map<String, String> hashMapReceived = (Map<String, String>) result.get(2);
  Iterator<String> iterator = hashMapReceived.keySet().iterator();
  String mapKey1 = iterator.next();
  String mapKey2 = iterator.next();
  assertFalse(iterator.hasNext());
  verifyHasBothValues(mapKey1, mapKey2, field1, field2);
  String mapValue1 = hashMapReceived.get(mapKey1);
  String mapValue2 = hashMapReceived.get(mapKey2);
  verifyHasBothValues(mapValue1, mapValue2, value1, value2);

  assertTrue(result.get(3) instanceof JedisDataException);
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:66,代码来源:PipeliningTest.java

示例13: after

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
List<Object> after(Pipeline pipeline) {
    Response<List<Object>> txOutput = pipeline.exec();
    pipeline.syncAndReturnAll();
    return txOutput.get();
}
 
开发者ID:andrepnh,项目名称:jedis-utils,代码行数:7,代码来源:PipelinedTransactedCommandBlock.java


注:本文中的redis.clients.jedis.Pipeline.exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。