@Override public void pipelineCommand(Pipeline pipeline, List<String> pipelineKeys) { for (String key : pipelineKeys) { String value = keyValueMap.get(key); pipeline.set(key, value); } }
pipeline.setex(key, expireIntervalSec, value); } else { pipeline.set(key, value);
@Override public void pipelineCommand(Pipeline pipeline, List<String> pipelineKeys) { for (String key : pipelineKeys) { byte[] value = keyValueMap.get(key); pipeline.set(SafeEncoder.encode(key), value); } }
@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); } }
@Override Response<String> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.set(key, value); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.SET.name(), duration, TimeUnit.MICROSECONDS); } }
@Override Response<String> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.set(key, value); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.SET.name(), duration, TimeUnit.MICROSECONDS); } }
@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"); }
private void testPipeline(byte[] key, byte[] value) { while (!stop.get()) { try (Jedis jedis = pool.getResource()) { Pipeline p = jedis.pipelined(); for (int i = 0; i < pipeline / 2; i++) { p.set(key, value); p.get(key); } p.sync(); reqCount.addAndGet(pipeline); } } }
@Override public Response<String> set(String key, String value) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value)); }
@Override public Response<String> set(byte[] key, byte[] value, byte[] nxxx) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, nxxx)); }
@Override public Response<String> set(byte[] key, byte[] value) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value)); }
@Override public Response<String> set(byte[] key, byte[] value, byte[] nxxx, byte[] expx, int time) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, nxxx, expx, time)); }
@Override public Response<String> set(String key, String value, String nxxx) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, nxxx)); }
@Override public Response<String> set(String key, String value, String nxxx, String expx, int time) { String command = "set"; return instrumented(command, payloadSize(value), () -> delegated.set(key, value, nxxx, expx, time)); }
@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 static void main(String[] args) { try (Jedis jedis = JedisUtil.getInstance().getJedis()) { long start = System.currentTimeMillis(); jedis.flushDB(); Pipeline p = jedis.pipelined(); for (int i = 0; i < 10000; i++) { p.set("age2" + i, i + ""); System.out.println(p.get("age2" + i)); } p.sync();// 这段代码获取所有的response long end = System.currentTimeMillis(); System.out.println("use pipeline cost:" + (end - start) + "ms"); } }
private void writeUsingSetCommand(KV<String, String> record, Long expireTime) { String key = record.getKey(); String value = record.getValue(); if (expireTime != null) { pipeline.psetex(key, expireTime, value); } else { pipeline.set(key, value); } }
public void set(KvItem item) { redis.pipeline(pipe -> { pipe.set(keyForItem(item.getKey()), item.getValue().toString()); pipe.sadd(globalAllKeys, item.getKey()); pipe.incr(keyForVersion(item.getKey())); pipe.incr(globalVersionKey); }); }
@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); } }