redis.clients.jedis.Pipeline.syncAndReturnAll()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(695)

本文整理了Java中redis.clients.jedis.Pipeline.syncAndReturnAll()方法的一些代码示例,展示了Pipeline.syncAndReturnAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pipeline.syncAndReturnAll()方法的具体详情如下:
包路径:redis.clients.jedis.Pipeline
类名称:Pipeline
方法名:syncAndReturnAll

Pipeline.syncAndReturnAll介绍

[英]Synchronize pipeline by reading all responses. This operation close the pipeline. Whenever possible try to avoid using this version and use Pipeline.sync() as it won't go through all the responses and generate the right response type (usually it is a waste of time).
[中]通过读取所有响应来同步管道。这次行动关闭了管道。尽可能避免使用此版本,并使用管道。sync(),因为它不会遍历所有响应并生成正确的响应类型(通常这是浪费时间)。

代码示例

代码示例来源:origin: changmingxie/tcc-transaction

@Override
  public List<Transaction> doInJedis(Jedis jedis) {
    Pipeline pipeline = jedis.pipelined();
    for (final byte[] key : keys) {
      pipeline.hgetAll(key);
    }
    List<Object> result = pipeline.syncAndReturnAll();
    List<Transaction> list = new ArrayList<Transaction>();
    for (Object data : result) {
      if (data != null && ((Map<byte[], byte[]>) data).size() > 0) {
        list.add(ExpandTransactionSerializer.deserialize(serializer, (Map<byte[], byte[]>) data));
      }
    }
    return list;
  }
});

代码示例来源:origin: sohutv/cachecloud

pipeline = jedis.pipelined();
  pipelineCommand(pipeline, subkeys);
  subResultList = pipeline.syncAndReturnAll();
} catch (JedisConnectionException e) {
  logger.error("RedisConnectionError-{}:{} keys={}", jedisPool.getHost(), jedisPool.getPort(), subkeys);

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public List<Object> syncAndReturnAll() {
 String command = "syncAndReturnAll";
 return instrumented(command, () -> delegated.syncAndReturnAll());
}

代码示例来源:origin: Baqend/Orestes-Bloomfilter

@Override
public List<Long> getRemainingTTLs(List<T> elements, TimeUnit unit) {
  try (Jedis jedis = pool.getResource()) {
    // Retrieve scores from Redis
    Pipeline pipe = jedis.pipelined();
    elements.forEach(it -> pipe.zscore(keys.TTL_KEY, it.toString()));
    List<Object> scores = pipe.syncAndReturnAll();
    // Convert to desired time
    return scores
      .stream()
      .map(score -> (Double) score)
      .map(score -> scoreToRemainingTTL(score, unit))
      .collect(Collectors.toList());
  }
}

代码示例来源:origin: intsmaze/intsmaze

@Test
public void testPipelined() {
  Pipeline pipeline = jedis.pipelined();
  long start = System.currentTimeMillis();
  for (int i = 0; i < 1000; 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");
}

代码示例来源:origin: Baqend/Orestes-Bloomfilter

@Override
public List<Boolean> isKnown(List<T> elements) {
  try (Jedis jedis = pool.getResource()) {
    // Retrieve scores from Redis
    Pipeline pipe = jedis.pipelined();
    elements.forEach(it -> pipe.zscore(keys.TTL_KEY, it.toString()));
    List<Object> scores = pipe.syncAndReturnAll();
    long endOfGracePeriod = now() - config.gracePeriod();
    // Convert to boolean
    return scores
        .stream()
        .map(score -> score != null && ((Double) score).longValue() > endOfGracePeriod)
        .collect(Collectors.toList());
  }
}

代码示例来源:origin: intsmaze/intsmaze

@Test
public void testPipelineTrans() {
  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 SET: " + ((end - start)/1000.0) + " seconds");
}

代码示例来源:origin: com.netflix.dyno/dyno-jedis

public List<Object> syncAndReturnAll() {
  long startTime = System.nanoTime() / 1000;
  try {
    List<Object> result = jedisPipeline.syncAndReturnAll();
    opMonitor.recordPipelineSync();
    return result;
  } catch (JedisConnectionException jce) {
    String msg = "Failed syncAndReturnAll() to host: " + getHostInfo();
    pipelineEx.set(new FatalConnectionException(msg, jce).
        setHost(connection == null ? Host.NO_HOST : connection.getHost()));
    cpMonitor.incOperationFailure(connection == null ? null : connection.getHost(), jce);
    throw jce;
  } finally {
    long duration = System.nanoTime() / 1000 - startTime;
    opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS);
    discardPipeline(false);
    releaseConnection();
  }
}

代码示例来源:origin: tangyanbo/springmore

/**
 * 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);
  }
}

代码示例来源:origin: RedisLabs/redis-quartz

p.zrem(RedisTriggerState.COMPLETED.getKey(), triggerHashKey);
p.zrem(RedisTriggerState.ERROR.getKey(), triggerHashKey);
List<Object> results = p.syncAndReturnAll();

代码示例来源:origin: tonivade/claudb

p.get("a");
Iterator<Object> result = p.syncAndReturnAll().iterator();
assertThat(result.next(), equalTo("PONG"));
assertThat(result.next(), equalTo("Hi!"));

相关文章

Pipeline类方法