當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。