Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisCluster that can use ReadOnly slaves #1789

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ define REDIS_CLUSTER_NODE1_CONF
daemonize yes
protected-mode no
requirepass cluster
masterauth cluster
port 7379
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node1.pid
Expand All @@ -159,6 +160,7 @@ define REDIS_CLUSTER_NODE2_CONF
daemonize yes
protected-mode no
requirepass cluster
masterauth cluster
port 7380
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node2.pid
Expand All @@ -173,6 +175,7 @@ define REDIS_CLUSTER_NODE3_CONF
daemonize yes
protected-mode no
requirepass cluster
masterauth cluster
port 7381
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node3.pid
Expand All @@ -187,6 +190,7 @@ define REDIS_CLUSTER_NODE4_CONF
daemonize yes
protected-mode no
requirepass cluster
masterauth cluster
port 7382
cluster-node-timeout 50
pidfile /tmp/redis_cluster_node4.pid
Expand All @@ -201,6 +205,7 @@ define REDIS_CLUSTER_NODE5_CONF
daemonize yes
protected-mode no
requirepass cluster
masterauth cluster
port 7383
cluster-node-timeout 5000
pidfile /tmp/redis_cluster_node5.pid
Expand All @@ -211,6 +216,21 @@ cluster-enabled yes
cluster-config-file /tmp/redis_cluster_node5.conf
endef

define REDIS_CLUSTER_NODE6_CONF
daemonize yes
protected-mode no
requirepass cluster
masterauth cluster
port 7384
cluster-node-timeout 5000
pidfile /tmp/redis_cluster_node6.pid
logfile /tmp/redis_cluster_node6.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_cluster_node6.conf
endef

#STUNNEL
define STUNNEL_CONF
cert = src/test/resources/private.pem
Expand All @@ -236,6 +256,7 @@ export REDIS_CLUSTER_NODE2_CONF
export REDIS_CLUSTER_NODE3_CONF
export REDIS_CLUSTER_NODE4_CONF
export REDIS_CLUSTER_NODE5_CONF
export REDIS_CLUSTER_NODE6_CONF
export STUNNEL_CONF
export STUNNEL_BIN

Expand Down Expand Up @@ -265,6 +286,7 @@ start: stunnel cleanup
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE4_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE5_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE6_CONF" | redis-server -

cleanup:
- rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null
Expand All @@ -291,6 +313,7 @@ stop:
kill `cat /tmp/redis_cluster_node3.pid` || true
kill `cat /tmp/redis_cluster_node4.pid` || true
kill `cat /tmp/redis_cluster_node5.pid` || true
kill `cat /tmp/redis_cluster_node6.pid` || true
kill `cat /tmp/stunnel.pid` || true
rm -f /tmp/sentinel1.conf
rm -f /tmp/sentinel2.conf
Expand All @@ -300,6 +323,7 @@ stop:
rm -f /tmp/redis_cluster_node3.conf
rm -f /tmp/redis_cluster_node4.conf
rm -f /tmp/redis_cluster_node5.conf
rm -f /tmp/redis_cluster_node6.conf

test: compile-module start
sleep 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package redis.clients.jedis;

import redis.clients.jedis.util.SafeEncoder;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class AbstractJedisClusterInfoCache {
public abstract JedisPool setupNodeIfNotExist(HostAndPort hostAndPort);

public abstract Map<String, JedisPool> getNodes();

public abstract Map<String, JedisPool> getNodes(ReadFrom readFrom);

public abstract void discoverClusterNodesAndSlots(Jedis jedis);

public abstract void renewClusterSlots(Jedis jedis);

public abstract void reset();

public abstract List<JedisPool> getShuffledNodesPool(ReadFrom readFrom);

public abstract JedisPool getSlotPool(int slot, ReadFrom readFrom);

public static String getNodeKey(HostAndPort hnp) {
return hnp.getHost() + ":" + hnp.getPort();
}

public static String getNodeKey(Client client) {
return client.getHost() + ":" + client.getPort();
}

public static String getNodeKey(Jedis jedis) {
return getNodeKey(jedis.getClient());
}

protected HostAndPort generateHostAndPort(List<Object> hostInfos) {
return new HostAndPort(SafeEncoder.encode((byte[]) hostInfos.get(0)),
((Long) hostInfos.get(1)).intValue());
}

protected List<Integer> getAssignedSlotArray(List<Object> slotInfo) {
List<Integer> slotNums = new ArrayList<Integer>();
for (int slot = ((Long) slotInfo.get(0)).intValue(); slot <= ((Long) slotInfo.get(1))
.intValue(); slot++) {
slotNums.add(slot);
}
return slotNums;
}
}
Loading