當前位置: 首頁>>代碼示例>>Java>>正文


Java Pipeline.syncAndReturnAll方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Pipeline.syncAndReturnAll方法的典型用法代碼示例。如果您正苦於以下問題:Java Pipeline.syncAndReturnAll方法的具體用法?Java Pipeline.syncAndReturnAll怎麽用?Java Pipeline.syncAndReturnAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Pipeline的用法示例。


在下文中一共展示了Pipeline.syncAndReturnAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test5

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private static void test5() {
    System.out.println("Test: [raw/pipeline] single instance");
    Jedis client = new Jedis(HOST);
    long t1 = System.currentTimeMillis();
    try {
        Pipeline p = client.pipelined();
        for (int i = 0; i < NUM_RUNS; i++) {
            p.get(SafeEncoder.encode("DEMO"));
        }
        List<Object> result = p.syncAndReturnAll();
        System.out.println(result);
    } finally {
        client.close();
    }
    long t2 = System.currentTimeMillis();
    System.out.println("Get [" + NUM_RUNS + "] times in " + (t2 - t1) + " ms.");
    System.out.println("Speed: " + ((double) NUM_RUNS * 1000) / (t2 - t1) + " gets/sec");
    System.out.println();
}
 
開發者ID:DDTH,項目名稱:ddth-redis,代碼行數:20,代碼來源:QndTestRedisClient.java

示例2: scheduleMulti

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Add multiple jobs to the TimeBasedJobScheduler, using a pipeline command to avoid O(n) network round trips.
 * Note that this implementation does not support quiescence.
 * @see #schedule(String, String, long, long)
 *
 * @param tube Used in conjunction with the redisPrefixKey (constructor) to make up the full redis key name.
 * @param jobStrs String representations of the jobs to be scheduled
 * @param millisInFuture The "priority" of the job in terms of the number of millis in the future that this job should become available.
 * @return number of newly scheduled jobs
 */
public int scheduleMulti(final String tube, final Iterable<String> jobStrs, final long millisInFuture) {
    try (Handle handle = rdbi.open()) {
        final Pipeline pl = handle.jedis().pipelined();
        for (String jobStr : jobStrs) {
            pl.zadd(getReadyQueue(tube),
                    Instant.now().getMillis() + millisInFuture,
                    jobStr);
        }
        int numAdded = 0;
        for (Object rslt : pl.syncAndReturnAll()) {
            numAdded += (Long) rslt;
        }
        return numAdded;
    }
}
 
開發者ID:lithiumtech,項目名稱:rdbi,代碼行數:26,代碼來源:TimeBasedJobScheduler.java

示例3: execute

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public List<Entry> execute() {
    Jedis conn = pool.getResource();
    Pipeline pipe = conn.pipelined();

    String tmpKey = root.execute(pipe);


    pipe.zrevrangeWithScores(tmpKey, query.sort.offset, query.sort.offset + query.sort.limit);

    List<Object> res = pipe.syncAndReturnAll();
    conn.close();


    Set<Tuple> ids = (Set<Tuple>) res.get(res.size() - 1);
    List<Entry> entries = new ArrayList<>(ids.size());
    for (Tuple t : ids) {
        entries.add(new Entry(t.getElement(), t.getScore()));
    }
    return entries;
}
 
開發者ID:RedisLabs,項目名稱:ReSearch,代碼行數:21,代碼來源:FullTextFacetedIndex.java

示例4: testSyncWithNoCommandQueued

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testSyncWithNoCommandQueued() {
  // we need to test with fresh instance of Jedis
  Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);

  Pipeline pipeline = jedis2.pipelined();
  pipeline.sync();

  jedis2.close();

  jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);

  pipeline = jedis2.pipelined();
  List<Object> resp = pipeline.syncAndReturnAll();
  assertTrue(resp.isEmpty());

  jedis2.close();
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:19,代碼來源:PipeliningTest.java

示例5: hashMultiGet

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public List<String> hashMultiGet(String[] mapNames, String[] fieldNames) {
    if (mapNames.length != fieldNames.length) {
        throw new IllegalArgumentException(
                "List of map names and list of field names must have same number of elements!");
    }
    Pipeline p = redisClient.pipelined();
    for (int i = 0; i < mapNames.length; i++) {
        String mapName = mapNames[i];
        String fieldName = fieldNames[i];
        p.hget(mapName, fieldName);
    }
    List<?> result = p.syncAndReturnAll();
    return (List<String>) result;
}
 
開發者ID:DDTH,項目名稱:ddth-redis,代碼行數:20,代碼來源:JedisRedisClient.java

示例6: hashMultiGetAsBinary

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public List<byte[]> hashMultiGetAsBinary(String[] mapNames, String[] fieldNames) {
    if (mapNames.length != fieldNames.length) {
        throw new IllegalArgumentException(
                "List of map names and list of field names must have same number of elements!");
    }
    Pipeline p = redisClient.pipelined();
    for (int i = 0; i < mapNames.length; i++) {
        byte[] mapName = SafeEncoder.encode(mapNames[i]);
        byte[] fieldName = SafeEncoder.encode(fieldNames[i]);
        p.hget(mapName, fieldName);
    }
    List<?> result = p.syncAndReturnAll();
    return (List<byte[]>) result;
}
 
開發者ID:DDTH,項目名稱:ddth-redis,代碼行數:20,代碼來源:JedisRedisClient.java

示例7: testPipelining

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Pipelining
 * 測試時間:0.287 seconds
 */
@Test
@Ignore
public void testPipelining(){
	Jedis jedis = new Jedis("localhost");
	Pipeline pipeline = jedis.pipelined();
	long start = System.currentTimeMillis();
	for(int i = 0; i< COUNTER; i++){
		pipeline.set("p" + i, "p" + i);
		if(i == 100){
			System.out.println(jedis.get("p1"));
		}
	}
	List<Object> results = pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	logger.info("Pipelined SET: " + ((end - start)/1000.0) + " seconds");
	jedis.close();
	System.out.println("result: " + results.get(0));
	System.out.println(jedis.get("p1"));
}
 
開發者ID:leopardoooo,項目名稱:easyooo-framework,代碼行數:24,代碼來源:JedisApiTest.java

示例8: pipeline

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void pipeline() throws UnsupportedEncodingException {
  Pipeline p = jedis.pipelined();
  p.set("foo", "bar");
  p.get("foo");
  List<Object> results = p.syncAndReturnAll();

  assertEquals(2, results.size());
  assertEquals("OK", results.get(0));
  assertEquals("bar", results.get(1));

}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:13,代碼來源:PipeliningTest.java

示例9: 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

示例10: testPipelined

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public void testPipelined() {// 0.076秒
	Jedis jedis = new Jedis("120.25.241.144", 6379);
	jedis.auth("b840fc02d52404542994");

	long start = System.currentTimeMillis();
	Pipeline pipeline = jedis.pipelined();
	for (int i = 0; i < 1000; i++) {
		pipeline.set("n" + i, "n" + i);
		System.out.println(i);
	}
	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,代碼行數:22,代碼來源:RedisExample.java

示例11: 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

示例12: processElement

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@ProcessElement
public void processElement(ProcessContext processContext) throws Exception {
  ScanParams scanParams = new ScanParams();
  scanParams.match(processContext.element());

  String cursor = ScanParams.SCAN_POINTER_START;
  boolean finished = false;
  while (!finished) {
    ScanResult<String> scanResult = jedis.scan(cursor, scanParams);
    List<String> keys = scanResult.getResult();

    Pipeline pipeline = jedis.pipelined();
    if (keys != null) {
      for (String key : keys) {
        pipeline.get(key);
      }
      List<Object> values = pipeline.syncAndReturnAll();
      for (int i = 0; i < values.size(); i++) {
        processContext.output(KV.of(keys.get(i), (String) values.get(i)));
      }
    }

    cursor = scanResult.getStringCursor();
    if (cursor.equals("0")) {
      finished = true;
    }
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:29,代碼來源:RedisIO.java

示例13: execute

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Execute with a call back action with result in pipeline.
 */
public List<Object> execute(PipelineAction pipelineAction) throws JedisException {
	Jedis jedis = null;
	boolean broken = false;
	try {
		jedis = jedisPool.getResource();
		Pipeline pipeline = jedis.pipelined();
		pipelineAction.action(pipeline);
		return pipeline.syncAndReturnAll();
	} catch (JedisException e) {
		broken = handleJedisException(e);
		throw e;
	} finally {
		closeResource(jedis, broken);
	}
}
 
開發者ID:pengqiuyuan,項目名稱:g2,代碼行數:19,代碼來源:JedisTemplate.java

示例14: test3Pipelined

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void test3Pipelined() {
	Pipeline pipeline = jedis.pipelined();
	long start = System.currentTimeMillis();
	for (int i = 0; i < 100000; i++) {
		pipeline.set("p" + i, "p" + i);
	}
	// System.out.println(pipeline.get("p1000").get());
	List<Object> results = pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	System.out.println("Pipelined SET: " + ((end - start) / 1000.0) + " seconds");
}
 
開發者ID:dreajay,項目名稱:jcode,代碼行數:13,代碼來源:TestJedis.java

示例15: 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


注:本文中的redis.clients.jedis.Pipeline.syncAndReturnAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。