Client Connection Research (SPRING/JEDIS) after Redis cluster cluster is built (to be practiced)

Source: Internet
Author: User

Tags: time app container print operation get targe public test

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 Edition -    <BeanID= "Jediscluster"class= "Redis.clients.jedis.JedisCluster">        <Constructor-arg>            <Set>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.xx.xx"/>                    <Constructor-argname= "Port"value= "9001"/>                 </Bean>                                                         <Beanclass= "Redis.clients.jedis.HostAndPort">                      <Constructor-argname= "Host"value= "XXXXXXX"/>                    <Constructor-argname= "Port"value= "9002"/>                 </Bean>                                                         <Beanclass= "Redis.clients.jedis.HostAndPort">                      <Constructor-argname= "Host"value= "XXXXXXX"/>                    <Constructor-argname= "Port"value= "9003"/>                 </Bean>                                                         <Beanclass= "Redis.clients.jedis.HostAndPort">                      <Constructor-argname= "Host"value= "XXXXXXX"/>                    <Constructor-argname= "Port"value= "9004"/>                 </Bean>                                                         <Beanclass= "Redis.clients.jedis.HostAndPort">                      <Constructor-argname= "Host"value= "XXXXXXX"/>                    <Constructor-argname= "Port"value= "9005"/>                 </Bean>                                                         <Beanclass= "Redis.clients.jedis.HostAndPort">                      <Constructor-argname= "Host"value= "XXXXXXX"/>                    <Constructor-argname= "Port"value= "9006"/>                </Bean>            </Set>        </Constructor-arg>    </Bean><BeanID= "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 *@authorXiao **/   Public classJedisclientclusterImplementsjedisclient{//Inject Jediscluster@AutowiredPrivateJediscluster Jediscluster; /*** Set String data type * *@paramKey *@paramValue *@return       */@Override Publicstring Set (String key, String value) {returnJediscluster.set (key, value); }        /*** Get String data type * *@paramKey *@return       */@Override Publicstring Get (String key) {returnJediscluster.get (key); }            /*** Set HASH data type * *@paramKey *@paramItem *@paramValue *@return       */@Override PublicLong Hset (string key, string item, String value) {returnJediscluster.hset (key, item, value); }            /*** Get Hash data type * *@paramKey *@paramItem *@return       */@Override Publicstring Hget (String key, string item) {returnjediscluster.hget (key, item); }            /*** Delete hash data *@paramKey *@paramItem *@return       */@Override PublicLong incr (String key) {returnJEDISCLUSTER.INCR (key); }            /*** Add an action * *@paramKey *@return       */@Override PublicLong decr (String key) {returnJEDISCLUSTER.DECR (key); }            /*** Minus One operation * *@paramKey *@return       */@Override PublicLong expire (String key,intsecond) {          returnJediscluster.expire (key, second); }            /*** Set expiration time of key * *@paramKey *@paramSecond *@return       */@Override PublicLong TTL (String key) {returnJediscluster.ttl (key); }            /*** Determine if key expires * *@paramKey *@return       */@Override PublicLong Hdel (string key, string item) {returnJediscluster.hdel (key, item); }    }  

Test:

@Test Public voidTestjedisclientspring ()throwsException {//Create a spring containerApplicationContext ApplicationContext =NewClasspathxmlapplicationcontext ("Classpath:spring/applicationcontext-*.xml"); //get the Jedisclient object from the containerJedisclient jedisclient = Applicationcontext.getbean (jedisclient.class); //jedisclient Operating RedisJedisclient.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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: