@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; } });
pipeline = jedis.pipelined(); pipelineCommand(pipeline, subkeys); subResultList = pipeline.syncAndReturnAll(); } catch (JedisConnectionException e) { logger.error("RedisConnectionError-{}:{} keys={}", jedisPool.getHost(), jedisPool.getPort(), subkeys);
@Override public List<Object> syncAndReturnAll() { String command = "syncAndReturnAll"; return instrumented(command, () -> delegated.syncAndReturnAll()); }
@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()); } }
@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"); }
@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()); } }
@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"); }
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(); } }
/** * 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); } }
p.zrem(RedisTriggerState.COMPLETED.getKey(), triggerHashKey); p.zrem(RedisTriggerState.ERROR.getKey(), triggerHashKey); List<Object> results = p.syncAndReturnAll();
p.get("a"); Iterator<Object> result = p.syncAndReturnAll().iterator(); assertThat(result.next(), equalTo("PONG")); assertThat(result.next(), equalTo("Hi!"));