当前位置: 首页>>代码示例>>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;未经允许,请勿转载。