<!--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