use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.
the class ClusterJedisCommandsTestBase method setUp.
@Before
public void setUp() throws InterruptedException {
node1 = new Jedis(nodeInfo1);
node1.auth("cluster");
node1.flushAll();
node2 = new Jedis(nodeInfo2);
node2.auth("cluster");
node2.flushAll();
node3 = new Jedis(nodeInfo3);
node3.auth("cluster");
node3.flushAll();
// ---- configure cluster
// add nodes to cluster
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());
// split available slots across the three nodes
// int slotsPerNode = JedisCluster.HASHSLOTS / 3;
int slotsPerNode = CLUSTER_HASHSLOTS / 3;
int[] node1Slots = new int[slotsPerNode];
int[] node2Slots = new int[slotsPerNode + 1];
int[] node3Slots = new int[slotsPerNode];
// for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) {
for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < CLUSTER_HASHSLOTS; i++) {
if (i < slotsPerNode) {
node1Slots[slot1++] = i;
} else if (i > slotsPerNode * 2) {
node3Slots[slot3++] = i;
} else {
node2Slots[slot2++] = i;
}
}
node1.clusterAddSlots(node1Slots);
node2.clusterAddSlots(node2Slots);
node3.clusterAddSlots(node3Slots);
waitForClusterReady();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
// cluster = new JedisCluster(jedisClusterNode, 2000, 2000, 5, "cluster", new JedisPoolConfig());
// cluster = new JedisCluster(jedisClusterNode, DefaultJedisClientConfig.builder().password("cluster").build(), 5);
cluster = new JedisCluster(jedisClusterNode, null, "cluster");
}
use of redis.clients.jedis.HostAndPort in project iris by chicc999.
the class JedisClusterFactory method parseHostAndPort.
private Set<HostAndPort> parseHostAndPort() throws Exception {
try {
Properties prop = new Properties();
prop.load(this.addressConfig.getInputStream());
Set<HostAndPort> haps = new HashSet<HostAndPort>();
for (Object key : prop.keySet()) {
if (!((String) key).startsWith(addressKeyPrefix)) {
continue;
}
String val = (String) prop.get(key);
boolean isIpPort = p.matcher(val).matches();
if (!isIpPort) {
throw new IllegalArgumentException("ip 或 port 不合法");
}
String[] ipAndPort = val.split(":");
HostAndPort hap = new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1]));
haps.add(hap);
}
return haps;
} catch (IllegalArgumentException ex) {
throw ex;
} catch (Exception ex) {
throw new Exception("解析 jedis 配置文件失败", ex);
}
}
use of redis.clients.jedis.HostAndPort in project druid by druid-io.
the class RedisClusterCacheTest method setUp.
@Before
public void setUp() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(cacheConfig.getMaxTotalConnections());
poolConfig.setMaxIdle(cacheConfig.getMaxIdleConnections());
poolConfig.setMinIdle(cacheConfig.getMinIdleConnections());
// orginal MockJedisCluster does not provide full support for all public get/set interfaces
// some methods must be overriden for test cases
cache = new RedisClusterCache(new MockJedisCluster(Collections.singleton(new HostAndPort("localhost", 6379))) {
final ConcurrentHashMap<String, byte[]> cacheStorage = new ConcurrentHashMap<>();
@Override
public String setex(final byte[] key, final int seconds, final byte[] value) {
cacheStorage.put(StringUtils.encodeBase64String(key), value);
return null;
}
@Override
public byte[] get(final byte[] key) {
return cacheStorage.get(StringUtils.encodeBase64String(key));
}
@Override
public List<byte[]> mget(final byte[]... keys) {
mgetCount.incrementAndGet();
List<byte[]> ret = new ArrayList<>();
for (byte[] key : keys) {
String k = StringUtils.encodeBase64String(key);
byte[] value = cacheStorage.get(k);
ret.add(value);
}
return ret;
}
}, cacheConfig);
}
use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.
the class ClusterBinaryJedisCommandsTest method setUp.
@Before
public void setUp() throws InterruptedException {
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
node1.auth("cluster");
node1.flushAll();
node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
node2.auth("cluster");
node2.flushAll();
node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort());
node3.auth("cluster");
node3.flushAll();
// ---- configure cluster
// add nodes to cluster
node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
node1.clusterMeet("127.0.0.1", nodeInfo3.getPort());
// split available slots across the three nodes
int slotsPerNode = JedisCluster.HASHSLOTS / 3;
int[] node1Slots = new int[slotsPerNode];
int[] node2Slots = new int[slotsPerNode + 1];
int[] node3Slots = new int[slotsPerNode];
for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) {
if (i < slotsPerNode) {
node1Slots[slot1++] = i;
} else if (i > slotsPerNode * 2) {
node3Slots[slot3++] = i;
} else {
node2Slots[slot2++] = i;
}
}
node1.clusterAddSlots(node1Slots);
node2.clusterAddSlots(node2Slots);
node3.clusterAddSlots(node3Slots);
waitForClusterReady();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
jedisCluster = new JedisCluster(jedisClusterNode, 2000, 2000, 5, "cluster", new JedisPoolConfig());
}
use of redis.clients.jedis.HostAndPort in project jedis by xetorthio.
the class JedisSentinelPoolTest method initializeWithNotAvailableSentinelsShouldThrowException.
@Test(expected = JedisConnectionException.class)
public void initializeWithNotAvailableSentinelsShouldThrowException() {
Set<String> wrongSentinels = new HashSet<String>();
wrongSentinels.add(new HostAndPort("localhost", 65432).toString());
wrongSentinels.add(new HostAndPort("localhost", 65431).toString());
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, wrongSentinels);
pool.destroy();
}
Aggregations