The spring XML configuration of Redis

Source: Internet
Author: User

    <!--Cluster Edition configuration -    <BeanID= "Jediscluster"class= "Redis.clients.jedis.JedisCluster">        <Constructor-argname= "Nodes">            <Set>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.25.128"></Constructor-arg>                    <Constructor-argname= "Port"value= "7001"></Constructor-arg>                </Bean>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.25.128"></Constructor-arg>                    <Constructor-argname= "Port"value= "7002"></Constructor-arg>                </Bean>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.25.128"></Constructor-arg>                    <Constructor-argname= "Port"value= "7003"></Constructor-arg>                </Bean>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.25.128"></Constructor-arg>                    <Constructor-argname= "Port"value= "7004"></Constructor-arg>                </Bean>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.25.128"></Constructor-arg>                    <Constructor-argname= "Port"value= "7005"></Constructor-arg>                </Bean>                <Beanclass= "Redis.clients.jedis.HostAndPort">                    <Constructor-argname= "Host"value= "192.168.25.128"></Constructor-arg>                    <Constructor-argname= "Port"value= "7006"></Constructor-arg>                </Bean>            </Set>        </Constructor-arg>    </Bean>    <BeanID= "Jedisclientcluster"class= "Com.lamsey.jedis.JedisClientCluster">        < Propertyname= "Jediscluster"ref= "Jediscluster"/>                </Bean>

First configuration: The connection address of the cluster

View Jediscluster's source code:
Set set with parameter named nodes
Public Jediscluster (S-et nodes) {This    (nodes, default_timeout);  }

1. Therefore, the construction body is assigned a set of sets:


name= "Nodes"> <set>
......
</set> </constructor-arg>

2.HostAndPort belongs to another class, so create a bean:
To view the source code, you need to configure two properties:
Can be configured with both Propety and constructor methods
  Public Hostandport (String host, int port) {    this.host = host;    This.port = port;  }

  

<bean class= "Redis.clients.jedis.HostAndPort" >                    <constructor-arg name= "host" value= "192.168.25.128" ></constructor-arg>                    <constructor-arg name= "Port" value= "7001" ></constructor-arg> </ Bean>


Finally, it is used in conjunction with the implementation class:
<bean id= "Jedisclientcluster" class= "Com.lamsey.jedis.JedisClientCluster" >        <property name= " Jediscluster "ref=" Jediscluster "/>                </bean>
Because there are jediscluster set methods inside the implementation class, it is possible to assign values using the property.
 Public classJedisclientclusterImplementsjedisclient{PrivateJediscluster Jediscluster;  PublicJediscluster Getjediscluster () {returnJediscluster; }    Public void Setjediscluster (Jediscluster jediscluster) {this.jediscluster = Jediscluster; } @Override Publicstring Set (String key, String value) {returnJediscluster.set (key, value); }}

Once the cluster's connection address configuration is complete,

It can be used
Jediscluster.set (key, value);


Through this process analysis, is a relatively clear understanding of the bean and Java class connection between, hahaha.



The spring XML configuration of Redis

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.