Note: Whether or not a cluster has been set up, or what kind of client to use to connect, it is necessary to integrate all IP lists, and then randomly write to one of the IP.
The benefits of doing this:
1, after the random IP write, the Redis cluster agent layer will automatically write to one of the shards according to the Shard, the random IP is just a huge traffic problem to slow down an IP.
2, for the write dead IP problem, can through the dynamic configuration file or interface, observe the IP Update or node increase, re-instantiation, the original business does not affect, because the object itself to the GC also represents the current business has been completed.
The following are clusters based on the spring and Jedis implementations, while the back end is a redis cluster native cluster.
Of course, you can also hand-handwritten these clients and so on.
The principle is still to be studied, in the end is not just write these IP, the client will all maintain these connections, and then help to determine which is not available.
Another idea is to use Haproxy to aggregate an IP and then add those IPs, but it's not going to affect the Redis cluster mode without testing it.
I guess the client needs all the IP to be written, because it supports-moved 6918 127.0.0.1:7004 to fetch the data. These protocols should be implemented by the client.
And if it is based on Redis cluster mode, I guess I should not be able to use the Haproxy proxy to aggregate IP.
For the understanding of this model, refer to: http://www.searu.org/30194.html, when the cluster is in a stable state, all clients will eventually save a hash slot to the node mapping record, making the cluster very efficient: The client can send a command request directly to the correct node without steering, proxy, or any other entity (entiy) that could have a single point of failure (failure).
This should be done without the agent software to achieve the reason.
The following is a Spring+jedis-based configuration:
in S Add a JEdis configuration to the Pring configuration file . (three main three from,9001-9003 is the Lord,9004-9006 is from)
<!-- Configure redis client cluster version -->
<bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">
<constructor-arg>
<set>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.XX.XX"/>
<constructor-arg name="port" value="9001"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="XXXXXXX"/>
<constructor-arg name="port" value="9002"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="XXXXXXX"/>
<constructor-arg name="port" value="9003"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="XXXXXXX"/>
<constructor-arg name="port" value="9004"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="XXXXXXX"/>
<constructor-arg name="port" value="9005"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="XXXXXXX"/>
<constructor-arg name="port" value="9006"/>
</bean>
</set>
</constructor-arg>
</bean>
<bean id="jedisClientCluster" class="com.dianshang.rest.component.impl.JedisClientCluster"/>
Package R Some common operations for Edis (store string type, get string type, set expiration time, delete hash data, etc.)
/**
* redis operation tool class
* @author xiao
*
*/
Public class JedisClientCluster implements JedisClient{
//Inject jedisCluster
@Autowired
Private JedisCluster jedisCluster;
/**
* Set the String data type
*
* @param key
* @param value
* @return
*/
@Override
Public String set(String key, String value) {
Return jedisCluster.set(key, value);
}
/**
* Get the String data type
*
* @param key
* @return
*/
@Override
Public String get(String key) {
Return jedisCluster.get(key);
}
/**
* Set the hash data type
*
* @param key
* @param item
* @param value
* @return
*/
@Override
Public Long hset(String key, String item, String value) {
Return jedisCluster.hset(key, item, value);
}
/**
* Get the hash data type
*
* @param key
* @param item
* @return
*/
@Override
Public String hget(String key, String item) {
Return jedisCluster.hget(key, item);
}
/**
* Delete hash data
* @param key
* @param item
* @return
*/
@Override
Public Long incr(String key) {
Return jedisCluster.incr(key);
}
/**
* Plus one operation
*
* @param key
* @return
*/
@Override
Public Long decr(String key) {
Return jedisCluster.decr(key);
}
/**
* minus one operation
*
* @param key
* @return
*/
@Override
Public Long expire(String key, int second) {
Return jedisCluster.expire(key, second);
}
/**
* Set the expiration time of the key
*
* @param key
* @param second
* @return
*/
@Override
Public Long ttl(String key) {
Return jedisCluster.ttl(key);
}
/**
* Determine if the key has expired
*
* @param key
* @return
*/
@Override
Public Long hdel(String key, String item) {
Return jedisCluster.hdel(key, item);
}
}
Test:
@Test
Public void testJedisClientSpring() throws Exception {
/ / Create a spring container
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
/ / Get the JedisClient object from the container
JedisClient jedisClient = applicationContext.getBean(JedisClient.class);
//jedisClient operation redis
jedisClient.set("cliet1", "1000");
String string = jedisClient.get("cliet1");
System.out.println(string);
}
Reference:
http://blog.csdn.net/u010539352/article/details/51778242 (The above sections are transferred from this article)
http://blog.csdn.net/younger_z/article/details/51366791
http://m635674608.iteye.com/blog/2292236
Https://www.2cto.com/kf/201609/551965.html
Http://www.sojson.com/blog/203.html
Client Connection Research (SPRING/JEDIS) after Redis cluster cluster is built (to be practiced)