redis.clients.jedis.Pipeline类的使用及代码示例

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

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

Pipeline介绍

暂无

代码示例

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

case STRING:
  String[] keyValue = buildKeyValuesList(keyValues);
  jedis.mset(keyValue);
  if (this.options.expireIntervalSec > 0) {
    Pipeline pipe = jedis.pipelined();
    for (int i = 0; i < keyValue.length; i += 2) {
      pipe.expire(keyValue[i], this.options.expireIntervalSec);
    pipe.sync();
  jedis.hmset(description.getAdditionalKey(), keyValues);
  if (this.options.expireIntervalSec > 0) {
    jedis.expire(description.getAdditionalKey(), this.options.expireIntervalSec);

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

@Override
public Boolean set(byte[] key, byte[] value) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(value, "Value must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().set(key, value),
          Converters.stringToBooleanConverter()));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().set(key, value),
          Converters.stringToBooleanConverter()));
      return null;
    }
    return Converters.stringToBoolean(connection.getJedis().set(key, value));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public Long sAdd(byte[] key, byte[]... values) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(values, "Values must not be null!");
  Assert.noNullElements(values, "Values must not contain null elements!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().sadd(key, values)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().sadd(key, values)));
      return null;
    }
    return connection.getJedis().sadd(key, values);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

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

代码示例来源: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: 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: spring-projects/spring-data-redis

@Override
public Boolean hSet(byte[] key, byte[] field, byte[] value) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(field, "Field must not be null!");
  Assert.notNull(value, "Value must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().hset(key, field, value),
          JedisConverters.longToBoolean()));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().hset(key, field, value),
          JedisConverters.longToBoolean()));
      return null;
    }
    return JedisConverters.toBoolean(connection.getJedis().hset(key, field, value));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public Map<byte[], byte[]> hGetAll(byte[] key) {
  Assert.notNull(key, "Key must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().hgetAll(key)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().hgetAll(key)));
      return null;
    }
    return connection.getJedis().hgetAll(key);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public void hMSet(byte[] key, Map<byte[], byte[]> hashes) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(hashes, "Hashes must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newStatusResult(connection.getRequiredPipeline().hmset(key, hashes)));
      return;
    }
    if (isQueueing()) {
      transaction(connection.newStatusResult(connection.getRequiredTransaction().hmset(key, hashes)));
      return;
    }
    connection.getJedis().hmset(key, hashes);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public Long del(byte[]... keys) {
  Assert.noNullElements(keys, "Keys must not be null!");
  Assert.noNullElements(keys, "Keys must not contain null elements!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().del(keys)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().del(keys)));
      return null;
    }
    return connection.getJedis().del(keys);
  } catch (Exception ex) {
    throw connection.convertJedisAccessException(ex);
  }
}

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

pipeLine = ((Jedis) connection).pipelined();
if (resource != null && resource.isActive())
  Response response = ((Transaction) connection).zrangeByScore(getHashKey(tableName, valueAsStr), score,
      score);
  results = ((Jedis) connection).zrangeByScore(getHashKey(tableName, valueAsStr), score, score);
        ((Transaction) connection).hdel(getEncodedBytes(rowKey), column); // delete
        ((Transaction) connection).zrem(getHashKey(tableName, colName), rowKey); // delete
        ((Jedis) connection).hdel(getEncodedBytes(rowKey), column); // delete
        ((Jedis) connection).zrem(getHashKey(tableName, colName), rowKey); // delete
  pipeLine.sync();

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

if (isBoundTransaction())
  pipeline = ((Jedis) connection).pipelined();
      ((Transaction) connection).hmset(getEncodedBytes(redisKey), redisFields);
      ((Transaction) connection).zadd(getHashKey(tableName, inverseJoinKeyAsStr),
          getDouble(inverseJoinKeyAsStr), redisKey);
      ((Transaction) connection).zadd(getHashKey(tableName, joinKeyAsStr), getDouble(joinKeyAsStr),
          redisKey);
      ((Jedis) connection).hmset(getEncodedBytes(redisKey), redisFields);
      ((Jedis) connection).zadd(getHashKey(tableName, inverseJoinKeyAsStr),
          getDouble(inverseJoinKeyAsStr), redisKey);
      ((Jedis) connection).zadd(getHashKey(tableName, joinKeyAsStr), getDouble(joinKeyAsStr),
  pipeline.sync();

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

@Ignore
@Test
public void testOverflow() {
  Jedis jedis = new Jedis("localhost");
  Pipeline p = jedis.pipelined();
  p.multi();
  for (int i = 0; i < 10000; i++) {
    p.setbit("test", 1, true); //or any other call
  }
  Response<List<Object>> exec = p.exec();
  p.sync();
  exec.get();
}

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

try {
  jedis = redisState.getJedis();
  Pipeline pipeline = jedis.pipelined();
      case STRING:
        if (this.expireIntervalSec > 0) {
          pipeline.setex(key, expireIntervalSec, value);
        } else {
          pipeline.set(key, value);
        pipeline.hset(additionalKey, key, value);
        break;
      default:
    pipeline.expire(additionalKey, expireIntervalSec);
  pipeline.sync();
} finally {
  if (jedis != null) {

代码示例来源: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: spring-projects/spring-data-redis

@Override
public List<Object> exec() {
  try {
    if (isPipelined()) {
      pipeline(newJedisResult(getRequiredPipeline().exec(),
          new TransactionResultConverter<>(new LinkedList<>(txResults), JedisConverters.exceptionConverter())));
      return null;
    }
    if (transaction == null) {
      throw new InvalidDataAccessApiUsageException("No ongoing transaction. Did you forget to call multi?");
    }
    List<Object> results = transaction.exec();
    return !CollectionUtils.isEmpty(results)
        ? new TransactionResultConverter<>(txResults, JedisConverters.exceptionConverter()).convert(results)
        : results;
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  } finally {
    txResults.clear();
    transaction = null;
  }
}

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

@SuppressWarnings("unchecked")
public <T> List<T> transactionallyDo(Consumer<Pipeline> f, String... watch) {
  return (List<T>) safelyReturn(jedis -> {
    Pipeline p = jedis.pipelined();
    if (watch.length != 0) {
      p.watch(watch);
    }
    p.multi();
    f.accept(p);
    Response<List<Object>> exec = p.exec();
    p.sync();
    return exec.get();
  });
}

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

pipeLine = ((Jedis) this.pipeLineOrConnection).pipelined();
pipeLine.zadd(idx_Name, value, parentId.toString());
((Transaction) this.pipeLineOrConnection).zadd(idx_Name, value, parentId.toString());
pipeLine.sync();

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

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

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

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

相关文章

微信公众号

最新文章

更多

Pipeline类方法