Skip to content

Instantly share code, notes, and snippets.

@guyroyse
Created March 11, 2020 23:07
Show Gist options
  • Save guyroyse/944e982d5577e126ce3c4376c8b1c31f to your computer and use it in GitHub Desktop.
Save guyroyse/944e982d5577e126ce3c4376c8b1c31f to your computer and use it in GitHub Desktop.
package com.guyroyse.blogs.lettucevsjedis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
import redis.clients.jedis.Tuple;
import java.util.Set;
import java.util.stream.Collectors;
public class JedisPipelining {
private static final String YOUR_CONNECTION_STRING = "redis://:foobared@yourserver:6379/0";
public static void main(String[] args) {
Jedis jedis = new Jedis(YOUR_CONNECTION_STRING);
Pipeline p = jedis.pipelined();
p.set("foo", "bar");
Response<String> get = p.get("foo");
p.zadd("baz", 13, "alpha");
p.zadd("baz", 23, "bravo");
p.zadd("baz", 42, "charlie");
Response<Set<Tuple>> range = p.zrangeWithScores("baz", 0, -1);
p.sync();
jedis.close();
System.out.println(get.get()); // "bar"
System.out.println(range.get().stream()
.map(Object::toString)
.collect(Collectors.joining(" "))); // [alpha,13.0] [bravo,23.0] [charlie,42.0]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment