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

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

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

Pipeline.sync介绍

[英]Synchronize pipeline by reading all responses. This operation close the pipeline. In order to get return values from pipelined commands, capture the different Response<?> of the commands you execute.
[中]通过读取所有响应来同步管道。这次行动关闭了管道。为了从流水线命令中获取返回值,捕获不同的响应<?>你执行的命令的一部分。

代码示例

代码示例来源:origin: signalapp/Signal-Server

public void stopBatchOperation(BatchOperationHandle handle) {
 Pipeline pipeline = handle.pipeline;
 Jedis    jedis    = handle.jedis;
 pipeline.sync();
 redisPool.returnWriteResource(jedis);
}

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

public void clear() {
 if (isInMulti()) {
  discard();
 }
 sync();
}

代码示例来源:origin: alibaba/jetcache

@Override
protected CacheResult do_PUT_ALL(Map<? extends K, ? extends V> map, long expireAfterWrite, TimeUnit timeUnit) {
  if (map == null) {
    return CacheResult.FAIL_ILLEGAL_ARGUMENT;
  }
  try (Jedis jedis = pool.getResource()) {
    int failCount = 0;
    List<Response<String>> responses = new ArrayList<>();
    Pipeline p = jedis.pipelined();
    for (Map.Entry<? extends K, ? extends V> en : map.entrySet()) {
      CacheValueHolder<V> holder = new CacheValueHolder(en.getValue(), timeUnit.toMillis(expireAfterWrite));
      Response<String> resp = p.psetex(buildKey(en.getKey()), timeUnit.toMillis(expireAfterWrite), valueEncoder.apply(holder));
      responses.add(resp);
    }
    p.sync();
    for (Response<String> resp : responses) {
      if(!"OK".equals(resp.get())){
        failCount++;
      }
    }
    return failCount == 0 ? CacheResult.SUCCESS_WITHOUT_MSG :
        failCount == map.size() ? CacheResult.FAIL_WITHOUT_MSG : CacheResult.PART_SUCCESS_WITHOUT_MSG;
  } catch (Exception ex) {
    logError("PUT_ALL", "map(" + map.size() + ")", ex);
    return new CacheResult(ex);
  }
}

代码示例来源:origin: qiujiayu/AutoLoadCache

@Override
public void hset(byte[] key, byte[] field, byte[] value, int seconds) {
  Jedis jedis = shardedJedis.getShard(key);
  Pipeline pipeline = jedis.pipelined();
  pipeline.hset(key, field, value);
  pipeline.expire(key, seconds);
  pipeline.sync();
}

代码示例来源:origin: apache/storm

pipeline.sync();
} finally {
  if (jedis != null) {

代码示例来源:origin: spring-projects/spring-data-redis

private List<Object> convertPipelineResults() {
  List<Object> results = new ArrayList<>();
  getRequiredPipeline().sync();
  Exception cause = null;
  for (JedisResult result : pipelinedResults) {
    try {
      Object data = result.get();
      if (!result.isStatus()) {
        results.add(result.conversionRequired() ? result.convert(data) : data);
      }
    } catch (JedisDataException e) {
      DataAccessException dataAccessException = convertJedisAccessException(e);
      if (cause == null) {
        cause = dataAccessException;
      }
      results.add(dataAccessException);
    } catch (DataAccessException e) {
      if (cause == null) {
        cause = e;
      }
      results.add(e);
    }
  }
  if (cause != null) {
    throw new RedisPipelineException(cause, results);
  }
  return results;
}

代码示例来源:origin: signalapp/Signal-Server

public List<ClientContact> get(List<byte[]> tokens) {
 try (Jedis jedis = redisPool.getWriteResource()) {
  Pipeline               pipeline = jedis.pipelined();
  List<Response<byte[]>> futures  = new LinkedList<>();
  List<ClientContact>    results  = new LinkedList<>();
  try {
   for (byte[] token : tokens) {
    futures.add(pipeline.hget(DIRECTORY_KEY, token));
   }
  } finally {
   pipeline.sync();
  }
  IterablePair<byte[], Response<byte[]>> lists = new IterablePair<>(tokens, futures);
  for (Pair<byte[], Response<byte[]>> pair : lists) {
   try {
    if (pair.second().get() != null) {
     TokenValue    tokenValue    = objectMapper.readValue(pair.second().get(), TokenValue.class);
     ClientContact clientContact = new ClientContact(pair.first(), tokenValue.relay, tokenValue.voice, tokenValue.video);
     results.add(clientContact);
    }
   } catch (IOException e) {
    logger.warn("Deserialization Problem: ", e);
   }
  }
  return results;
 }
}

代码示例来源:origin: apache/storm

pipe.expire(keyValue[i], this.options.expireIntervalSec);
pipe.sync();

代码示例来源:origin: Impetus/Kundera

pipeLine.sync();

代码示例来源:origin: Impetus/Kundera

@Override
public void delete(Object entity, Object pKey)
{
  EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entity.getClass());
  Object connection = getConnection();
  Pipeline pipeLine = null;
  try
  {
    if (isBoundTransaction())
    {
      pipeLine = ((Jedis) connection).pipelined();
      onDelete(entity, pKey, pipeLine);
    }
    else
    {
      onDelete(entity, pKey, connection);
    }
    getIndexManager().remove(metadata, entity, pKey);
  }
  finally
  {
    if (pipeLine != null)
    {
      pipeLine.sync();
    }
    onCleanup(connection);
  }
}

代码示例来源:origin: Impetus/Kundera

@Override
protected void onPersist(EntityMetadata entityMetadata, Object entity, Object id, List<RelationHolder> rlHolders)
{
  Object connection = getConnection();
  // Create a hashset and populate data into it
  //
  Pipeline pipeLine = null;
  try
  {
    if (isBoundTransaction())
    {
      pipeLine = ((Jedis) connection).pipelined();
      onPersist(entityMetadata, entity, id, rlHolders, pipeLine);
    }
    else
    {
      onPersist(entityMetadata, entity, id, rlHolders, connection);
    }
  }
  finally
  {
    //
    if (pipeLine != null)
    {
      pipeLine.sync(); // send I/O.. as persist call. so no need to
               // read
    } // response?
    onCleanup(connection);
  }
}

代码示例来源:origin: Impetus/Kundera

pipeline.sync();

代码示例来源:origin: Impetus/Kundera

pipeLine.sync(); // send I/O.. as persist call. so no need to

代码示例来源:origin: stackoverflow.com

List<Response> responses = new ArrayList<>();

Pipeline p = jedis.pipelined();
for (int id: ids) {
records.add(p.get(id));
}
p.sync();

for(Reponse response : responses){
Object o = response.get();
}

代码示例来源:origin: Impetus/Kundera

pipeLine.sync();

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

public <T> void safeForEach(Collection<T> collection, BiConsumer<Pipeline, T> f) {
  safelyReturn(jedis -> {
    Pipeline p = jedis.pipelined();
    collection.stream().forEach(e -> f.accept(p, e));
    p.sync();
    return null;
  });
}

代码示例来源:origin: com.github.biezhi/unique-support-redis

@Override
  List<String> execute() {
    Pipeline pipeline = jedis.getShard(key).pipelined();
    Response<List<String>> result = pipeline.hmget(key, fields);
    pipeline.expire(key, expire);
    pipeline.sync();
    return result.get();
  }
}.getResult();

代码示例来源:origin: com.github.biezhi/unique-support-redis

@Override
  Long execute() {
    Pipeline pipeline = jedis.getShard(key).pipelined();
    Response<Long> result = pipeline.hlen(key);
    pipeline.expire(key, expire);
    pipeline.sync();
    return result.get();
  }
}.getResult();

代码示例来源:origin: com.github.biezhi/unique-support-redis

@Override
  Set<String> execute() {
    Pipeline pipeline = jedis.getShard(key).pipelined();
    Response<Set<String>> result = pipeline.hkeys(key);
    pipeline.expire(key, expire);
    pipeline.sync();
    return result.get();
  }
}.getResult();

代码示例来源:origin: com.github.biezhi/unique-support-redis

@Override
  Long execute() {
    Pipeline pipeline = jedis.getShard(key).pipelined();
    Response<Long> result = pipeline.lpush(key, value);
    // 修剪列表元素, 如果 size - 1 比 end 下标还要大,Redis将 size 的值设置为 end 。
    pipeline.ltrim(key, 0, size - 1);
    pipeline.sync();
    return result.get();
  }
}.getResult();

相关文章

Pipeline类方法