当前位置: 首页>>代码示例>>Java>>正文


Java ShardedJedis.pipelined方法代码示例

本文整理汇总了Java中redis.clients.jedis.ShardedJedis.pipelined方法的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedis.pipelined方法的具体用法?Java ShardedJedis.pipelined怎么用?Java ShardedJedis.pipelined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.ShardedJedis的用法示例。


在下文中一共展示了ShardedJedis.pipelined方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rename

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
 * Use transactions to add index file and then delete the old one
 *
 * @param fileLengthKey the key using for hash file length
 * @param fileDataKey   the key using for hash file data
 * @param oldField      the old hash field
 * @param newField      the new hash field
 * @param values        the data values of the old hash field
 * @param fileLength    the data length of the old hash field
 */
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    //add new file length
    pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
    //add new file content
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
    deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:28,代码来源:ShardedJedisPoolStream.java

示例2: saveFile

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
        if (i % Constants.SYNC_COUNT == 0) {
            pipelined.sync();
            pipelined = shardedJedis.pipelined();
        }
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:18,代码来源:ShardedJedisPoolStream.java

示例3: deleteFile

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
 * Use transactions to delete index file
 *
 * @param fileLengthKey the key using for hash file length
 * @param fileDataKey   the key using for hash file data
 * @param field         the hash field
 * @param blockSize     the index file data block size
 */
@Override
public void deleteFile(String fileLengthKey, String fileDataKey, String field, long blockSize) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    //delete file length
    pipelined.hdel(fileLengthKey.getBytes(), field.getBytes());
    //delete file content
    for (int i = 0; i < blockSize; i++) {
        byte[] blockName = getBlockName(field, i);
        pipelined.hdel(fileDataKey.getBytes(), blockName);
    }
    pipelined.sync();
    shardedJedis.close();
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:23,代码来源:ShardedJedisPoolStream.java

示例4: loadFileOnce

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
public List<byte[]> loadFileOnce(String fileDataKey, String fileName, long blockSize) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    List<byte[]> res = new ArrayList<>();
    List<Response<byte[]>> temps = new ArrayList<>();
    int temp = 0;
    //如果不分批次sync容易read time out和Java heap space
    while (temp < blockSize) {
        Response<byte[]> data = pipelined.hget(fileDataKey.getBytes(), getBlockName(fileName, temp));
        temps.add(data);
        if (temp % Constants.SYNC_COUNT == 0) {
            pipelined.sync();
            res.addAll(temps.stream().map(response -> uncompressFilter(response.get())).collect(Collectors.toList()));
            temps.clear();
            pipelined = shardedJedis.pipelined();
        }
        temp++;
    }
    try {
        pipelined.sync();
    } catch (JedisConnectionException e) {
        log.error("pipelined = {}, blockSize = {}!", pipelined.toString(), blockSize);
        log.error("", e);
    } finally {
        shardedJedis.close();
    }
    res.addAll(temps.stream().map(response -> uncompressFilter(response.get())).collect(Collectors.toList()));
    temps.clear();
    return res;
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:32,代码来源:ShardedJedisPoolStream.java

示例5: shardedPipeline

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Test
public void shardedPipeline() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  shards.get(0).setPassword("foobared");
  shards.get(1).setPassword("foobared");
  ShardedJedis jedis = new ShardedJedis(shards);

  final List<String> keys = getKeysDifferentShard(jedis);
  jedis.set(keys.get(0), "a");
  jedis.set(keys.get(1), "b");

  assertNotSame(jedis.getShard(keys.get(0)), jedis.getShard(keys.get(1)));

  List<Object> results = jedis.pipelined(new ShardedJedisPipeline() {
    public void execute() {
      get(keys.get(0));
      get(keys.get(1));
    }
  });

  List<Object> expected = new ArrayList<Object>(2);
  expected.add(SafeEncoder.encode("a"));
  expected.add(SafeEncoder.encode("b"));

  assertEquals(2, results.size());
  assertArrayEquals(SafeEncoder.encode("a"), (byte[]) results.get(0));
  assertArrayEquals(SafeEncoder.encode("b"), (byte[]) results.get(1));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:31,代码来源:ShardedJedisTest.java

示例6: returnResourceShouldResetState

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Test
public void returnResourceShouldResetState() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("pipelined", String.valueOf(0));
  jedis.set("pipelined2", String.valueOf(0));

  ShardedJedisPipeline pipeline = jedis.pipelined();

  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");

  jedis.resetState();

  pipeline = jedis.pipelined();
  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");
  List<Object> results = pipeline.syncAndReturnAll();

  assertEquals(2, results.size());
  pool.returnResource(jedis);
  pool.destroy();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:33,代码来源:ShardedJedisPoolTest.java


注:本文中的redis.clients.jedis.ShardedJedis.pipelined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。