Skip to content

Instantly share code, notes, and snippets.

@mp911de
Last active November 27, 2015 16:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mp911de/8369b765c2fa8586d48c to your computer and use it in GitHub Desktop.
Save mp911de/8369b765c2fa8586d48c to your computer and use it in GitHub Desktop.
Connecting a Redis Cluster
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import java.util.HashSet;
import java.util.Set;
public class JedisCluster {
public static void main(String[] args) {
Set<HostAndPort> connectionPoints = new HashSet<HostAndPort>();
connectionPoints.add(new HostAndPort("localhost", 7379));
JedisCluster cluster = new JedisCluster(connectionPoints);
cluster.set("key", "value");
System.out.println(cluster.get("key"));
cluster.close();
}
}
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection;
import com.lambdaworks.redis.cluster.RedisClusterClient;
public class LettuceCluster {
public static void main(String[] args) {
RedisClusterClient clusterClient = new RedisClusterClient(RedisURI.create("redis://localhost:7379"));
RedisAdvancedClusterConnection<String, String> cluster = clusterClient.connectCluster();
cluster.set("key", "value");
System.out.println(cluster.get("key"));
cluster.close();
clusterClient.shutdown();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>play</groupId>
<artifactId>play</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>3.3.Beta1</version>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment