Skip to content

Instantly share code, notes, and snippets.

@undeadcat
Created December 6, 2022 01:15
Show Gist options
  • Save undeadcat/b1b22acc324a1e61a9b0ac96daeca863 to your computer and use it in GitHub Desktop.
Save undeadcat/b1b22acc324a1e61a9b0ac96daeca863 to your computer and use it in GitHub Desktop.
Jedis multi-slot-pipeline test
package redis.clients.jedis;
import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.providers.ClusterConnectionProvider;
import java.util.Collections;
import java.util.HashSet;
public class ClusterPipeliningTest {
@Test
public void clusterPipelineSync() {
ClusterConnectionProvider provider = new ClusterConnectionProvider(new HashSet<>(Collections.singletonList(new HostAndPort("redis-cluster-host.internal", 6379))), DefaultJedisClientConfig.builder().build());
ClusterPipeline setPipeline = new ClusterPipeline(provider);
Response<String> s1 = setPipeline.set("foo", "1");
Response<String> s2 = setPipeline.set("foo2", "1");
Response<String> s3 = setPipeline.set("foo3", "1");
Response<String> s4 = setPipeline.set("foo4", "2");
setPipeline.sync();
Assert.assertEquals("OK", s1.get());
Assert.assertEquals("OK", s2.get());
Assert.assertEquals("OK", s3.get());
Assert.assertEquals("OK", s4.get());
ClusterPipeline getPipeline = new ClusterPipeline(provider);
Response<String> r1 = getPipeline.get("foo");
Response<String> r2 = getPipeline.get("foo2");
Response<String> r3 = getPipeline.get("foo3");
Response<String> r4 = getPipeline.get("foo4");
getPipeline.sync();
Assert.assertEquals("1", r1.get());
Assert.assertEquals("1", r2.get());
Assert.assertEquals("1", r3.get());
Assert.assertEquals("2", r4.get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment