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


Java Pipeline.sync方法代码示例

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


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

示例1: rename

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    long blockSize = 0;
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Pipeline pipelined = jedis.pipelined();
        //add new file length
        pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
        //add new file content
        blockSize = getBlockSize(fileLength);
        for (int i = 0; i < blockSize; i++) {
            pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
        }
        values.clear();
        pipelined.sync();
    } finally {
        jedis.close();
        deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
    }
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:23,代码来源:JedisPoolStream.java

示例2: deleteFile

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
/**
 * Use transactions to delete index file
 *
 * @param fileLengthKey
 * @param fileDataKey
 * @param field
 * @param blockSize
 */
@Override
public void deleteFile(String fileLengthKey, String fileDataKey, String field, long blockSize) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Pipeline pipelined = jedis.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();
    } finally {
        jedis.close();
    }
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:27,代码来源:JedisPoolStream.java

示例3: saveFile

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Pipeline pipelined = jedis.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 = jedis.pipelined();
            }
        }
        values.clear();
        pipelined.sync();
    } finally {
        jedis.close();
    }
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:22,代码来源:JedisPoolStream.java

示例4: rename

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    Jedis jedis = openJedis();
    Pipeline pipelined = jedis.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();
    jedis.close();
    values.clear();
    deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:18,代码来源:JedisStream.java

示例5: saveFile

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    Jedis jedis = openJedis();
    Pipeline pipelined = jedis.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 = jedis.pipelined();
        }
    }
    pipelined.sync();
    jedis.close();
    values.clear();
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:18,代码来源:JedisStream.java

示例6: main

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException, IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  Pipeline p = jedis.pipelined();
  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    String key = "foo" + n;
    p.set(key, "bar" + n);
    p.get(key);
  }
  p.sync();

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:23,代码来源:PipelinedGetSetBenchmark.java

示例7: testSync

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testSync() throws Exception {
  int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
  String key = presetElementKeys.get(rnd);
  String value = String.valueOf(presetElements.get(key));

  Pipeline pipeline = jedis.pipelined();

  Snapshot snapshot = commandTracker.snapshot();
  Snapshot discardSnapshot = discardTracker.snapshot();
  Snapshot txsnapshot = execTracker.snapshot();
  Snapshot pipelineSnapshot = pipelineTracker.snapshot();
  pipelineSnapshot.increment();
  Response<Long> added = pipeline.sadd(key, value);
  pipeline.sync();
  assertEquals(1, (long) added.get());
  pipelineSnapshot.validate();
  txsnapshot.validate();
  snapshot.validate();
  discardSnapshot.validate();
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:22,代码来源:JedisPipelineInstrumentationTest.java

示例8: containsKeys

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public boolean containsKeys(Collection<K> keys) {
    if (keys == null || keys.size() == 0) {
        return false;
    }
    // 使用 Redis 提供的管道进行批处理,提高效率
    Pipeline pipeline = jedisProxy.pipelined();
    Set<Response<Boolean>> responses = new HashSet<Response<Boolean>>(keys.size());
    for (K key : keys) {
        if (localMapCache != null && localMapCache.containsKey(key)) {
            continue;
        }
        responses.add(pipeline.hexists(SerializeUtil.serialize(getName()), SerializeUtil.serialize(key)));
    }
    if (responses.size() < 1) {
        return true;
    }
    pipeline.sync();
    for (Response<Boolean> response : responses) {
        if (!response.get()) {
            return false;
        }
    }
    return true;
}
 
开发者ID:ganpengyu,项目名称:gedis,代码行数:26,代码来源:ServerMapCache.java

示例9: gets

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public Map<K, V> gets(Collection<K> keys) {
    Map<K, V> result = new HashMap<>(keys.size());
    Pipeline pipeline = jedisProxy.pipelined();
    byte[] keyBytes = SerializeUtil.serialize(getName());
    Map<K, Response<byte[]>> responseMap = new HashMap<>(keys.size());
    for (K key : keys) {
        if (localMapCache != null && localMapCache.containsKey(key)) {
            result.put(key, localMapCache.get(key));
            continue;
        }
        responseMap.put(key, pipeline.hget(keyBytes, SerializeUtil.serialize(key)));
    }
    if (responseMap.size() < 1) {
        return result;
    }
    pipeline.sync();
    for (Map.Entry<K, Response<byte[]>> entry : responseMap.entrySet()) {
        result.put(entry.getKey(), (V) SerializeUtil.deserialize(entry.getValue().get()));
    }
    return result;
}
 
开发者ID:ganpengyu,项目名称:gedis,代码行数:23,代码来源:ServerMapCache.java

示例10: getAllFromRedis

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
private Table<String, ResourceType, Response<Map<String, String>>> getAllFromRedis(Set<String> userIds) {
  if (userIds.size() == 0) {
    return HashBasedTable.create();
  }
  try (Jedis jedis = jedisSource.getJedis()) {
    Table<String, ResourceType, Response<Map<String, String>>> responseTable =
        ArrayTable.create(userIds, new ArrayIterator<>(ResourceType.values()));

    Pipeline p = jedis.pipelined();
    for (String userId : userIds) {
      for (ResourceType r : ResourceType.values()) {
        responseTable.put(userId, r, p.hgetAll(userKey(userId, r)));
      }
    }
    p.sync();
    return responseTable;
  } catch (Exception e) {
    log.error("Storage exception reading all entries.", e);
  }
  return null;
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:22,代码来源:RedisPermissionsRepository.java

示例11: testEvalKeyAndArgWithBinary

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testEvalKeyAndArgWithBinary() {
  // binary
  byte[] bKey = SafeEncoder.encode("test");
  byte[] bArg = SafeEncoder.encode("3");
  byte[] bScript = SafeEncoder
      .encode("redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])");

  Pipeline bP = jedis.pipelined();
  bP.set(bKey, SafeEncoder.encode("0"));
  Response<Object> bResult0 = bP.eval(bScript, Arrays.asList(bKey), Arrays.asList(bArg));
  bP.incr(bKey);
  Response<Object> bResult1 = bP.eval(bScript, Arrays.asList(bKey), Arrays.asList(bArg));
  Response<byte[]> bResult2 = bP.get(bKey);
  bP.sync();

  assertNull(bResult0.get());
  assertNull(bResult1.get());
  assertArrayEquals(SafeEncoder.encode("13"), bResult2.get());
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:21,代码来源:PipeliningTest.java

示例12: pipelineWithTransaction

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
public void pipelineWithTransaction() {
  Jedis jedis = pool.getResource();
  try {
    Pipeline p = jedis.pipelined();
    p.multi();
    for (int i = 0; i < rowCount; i++) {
      String key = RandomStringUtils.randomAlphabetic(8);
      p.set(key, RandomStringUtils.randomNumeric(5));
      p.expire(key, 5 * 60);
    }
    p.exec();
    p.sync();
  } catch (Exception e) {
    pool.returnResource(jedis);
  }
}
 
开发者ID:nickevin,项目名称:Qihua,代码行数:17,代码来源:RedisTransactionTest.java

示例13: remove

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void remove(@NonNull String id) {
  try (Jedis jedis = jedisSource.getJedis()) {
    Map<String, String> userRolesById = jedis.hgetAll(userKey(id, ResourceType.ROLE));

    Pipeline p = jedis.pipelined();

    p.srem(allUsersKey(), id);
    for (String roleName : userRolesById.keySet()) {
      p.srem(roleKey(roleName), id);
    }

    for (ResourceType r : ResourceType.values()) {
      p.del(userKey(id, r));
    }
    p.sync();
  } catch (Exception e) {
    log.error("Storage exception reading " + id + " entry.", e);
  }
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:21,代码来源:RedisPermissionsRepository.java

示例14: run

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Override
public void run() {
    Thread.currentThread().setName("ConsumerThread-"+topicConfig.getTopic());
    try {
        while (running) {

            ConsumerRecords<String, String> records = consumer.poll(1000);
            logger.info(String.format("poll count:"+records.count()));
            Pipeline jedisPipe = jedis.pipelined();
            for (ConsumerRecord<String, String> record : records) {
                String key = record.key();
                String value = record.value();
                if(key!=null && value!=null) {
                    jedisPipe.set(key,value);
                }
            }
            jedisPipe.sync();
        }
    }finally {
        if (consumer!=null) {
            consumer.close();
        }
    }
}
 
开发者ID:xausky,项目名称:kafka-consumer-redis,代码行数:25,代码来源:ConsumerThread.java

示例15: testEvalshaKeyAndArg

import redis.clients.jedis.Pipeline; //导入方法依赖的package包/类
@Test
public void testEvalshaKeyAndArg() {
  String key = "test";
  String arg = "3";
  String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
  String sha1 = jedis.scriptLoad(script);

  assertTrue(jedis.scriptExists(sha1));

  Pipeline p = jedis.pipelined();
  p.set(key, "0");
  Response<Object> result0 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
  p.incr(key);
  Response<Object> result1 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
  Response<String> result2 = p.get(key);
  p.sync();

  assertNull(result0.get());
  assertNull(result1.get());
  assertEquals("13", result2.get());
}
 
开发者ID:Wangab,项目名称:Jedis,代码行数:22,代码来源:PipeliningTest.java


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