Last active
November 27, 2015 16:50
-
-
Save mp911de/8369b765c2fa8586d48c to your computer and use it in GitHub Desktop.
Connecting a Redis Cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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