Redis Cluster integration with Spring-data-redis

Source: Internet
Author: User
Tags redis version serialization redis cluster

Pits encountered: The following Jedis version and Spring-data-redis version must be used to achieve cluster effect. Version 1.7 was previously not supported for cluster

<dependency>    <groupId>redis.clients</groupId>    <artifactid>jedis</artifactid >    <version>2.8.0</version></dependency>        <dependency>                                <groupId> org.springframework.data</groupid>     <artifactId>spring-data-redis</artifactId>    < Version>1.7.1.release</version></dependency>

*********** cluster configuration **********

   <bean id= "Redispoolconfig" class= "Redis.clients.jedis.JedisPoolConfig" > <property name= "maxtotal" value = "${redis.maxtotal}"/> <property name= "Maxidle" value= "${redis.maxidle}"/> <property name= "max    Waitmillis "value=" ${redis.maxwait} "/> <property name=" Testonborrow "value=" ${redis.testonborrow} "/> </bean> <!--Configuring Redis node--<bean id= "redisclusterconfiguration" class= "Org.springfram Ework.data.redis.connection.RedisClusterConfiguration "> <property name=" maxredirects "value=" 3 "></ Property> <!--node configuration--<property name= "Clusternodes" > <set> <bean class= " Org.springframework.data.redis.connection.RedisClusterNode "> <constructor-arg name=" Host "value=" 192. 168.241.129 "></constructor-arg> <constructor-arg name=" Port "value=" 9006 "></constructor- Arg> </bean>           <bean class= "Org.springframework.data.redis.connection.RedisClusterNode" > <constructor- Arg name= "host" value= "192.168.241.129" ></constructor-arg> <constructor-arg name= "Port" value= "9001" ></constructor-arg> </bean> <bean class= "Org.springframework.data.redis.conn Ection.                Redisclusternode "> <constructor-arg name=" host "value=" 192.168.241.129 "></constructor-arg>            <constructor-arg name= "Port" value= "9002" ></constructor-arg> </bean> <bean class= "Org.springframework.data.redis.connection.RedisClusterNode" > <constructor-arg name= "Host" value= "192.168.241.129" ></constructor-arg> <constructor-arg name= "Port" value= "9003" > </constructor-arg> </bean> <bean class= "org.springframework.data.redis.connection.Red Isclusternode "; <constructor-arg name= "host" value= "192.168.241.129" ></constructor-arg> <constructor-arg Nam E= "Port" value= "9004" ></constructor-arg> </bean> <bean class= "org.springframework. Data.redis.connection.RedisClusterNode "> <constructor-arg name=" host "value=" 192.168.241.129 ">< /constructor-arg> <constructor-arg name= "Port" value= "9005" ></constructor-arg> &L t;/bean> </set> </property></bean> <bean id= "jedisconnectionfactory" class= "or G.springframework.data.redis.connection.jedis.jedisconnectionfactory "> <constructor-arg ref=" Redisclusterconfiguration "/> <constructor-arg ref=" Redispoolconfig "/></bean> <!--storage serialization- -<bean id= "Stringredisserializer" class= "Org.springframework.data.redis.serializer.StringRedisSerializer" /> <! --Redis Access template--><bean id= "redistemplate" class= "Org.springframework.data.redis.core.RedisTemplate" > <    Property Name= "ConnectionFactory" ref= "Jedisconnectionfactory"/> <!--Add the following serialization configuration to resolve key garbled problems and to make the keys () method Effective- <property name= "Keyserializer" ref= "Stringredisserializer"/> <property name= "HashKeySerializer" ref= "  Stringredisserializer "/></bean>

  

Single version configuration *******

<bean id= "Redispoolconfig"class= "Redis.clients.jedis.JedisPoolConfig" > <property name= "maxtotal" value= "${redis.maxtotal}"/> < Property Name= "Maxidle" value= "${redis.maxidle}"/> <property name= "Maxwaitmillis" value= "${redis.maxwait}"/    > <property name= "testonborrow" value= "${redis.testonborrow}"/> </bean> <!--standalone Configuration-- <!--configuration Jedisconnectionfactory--<bean id= "Jedisconnectionfactory"class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory" > <property name= "hostName" value= "127.0.0.1"/> <property name= "port" value= "6379"/> <!--<property name= "password" value= "${ Redis.pass} "/>-<property name=" Database "value=" 1 "/> <property name=" Poolconfig "ref=" R Edispoolconfig "/> </bean> <!--storage Serialization--<bean id=" Stringredisserializer "class= "Org.springframework.data.redis.serializer.StringRedisSerializer"/> <!--redis Access template-->& Lt;bean id= "Redistemplate"class= "Org.springframework.data.redis.core.RedisTemplate" > <property name= "connectionfactory" ref= " Jedisconnectionfactory "/> <!--Add the following serialization configuration to solve key garbled problems and make the keys () method Effective--<property name=" Keyserializer "ref=" Stringredisserializer "/> <property name=" Hashkeyserializer "ref=" Stringredisserializer "/></bean>

Introduced in Java code can be

@Autowiredprivate redistemplate template;

  

Redis Cluster integration with Spring-data-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.