Spring连接redis cluster的配置文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"

      xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"

      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


  <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">


      <property name="maxTotal" value="${redis.pool.maxTotal}" />


      <property name="maxIdle" value="${redis.pool.maxIdle}" />


      <property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />


      <property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />

</bean>


  <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">

<property name="maxRedirects" value="${redis.cluster.maxRedirects}"></property>

<property name="clusterNodes">

<set>

<bean class="org.springframework.data.redis.connection.RedisNode">

<constructor-arg name="host" value="${redis.cluster.host1}" />

<constructor-arg name="port" value="${redis.cluster.port1}" />

</bean>

<bean class="org.springframework.data.redis.connection.RedisNode">

<constructor-arg name="host" value="${redis.cluster.host2}" />

<constructor-arg name="port" value="${redis.cluster.port2}" />

</bean>

<bean class="org.springframework.data.redis.connection.RedisNode">

<constructor-arg name="host" value="${redis.cluster.host3}" />

<constructor-arg name="port" value="${redis.cluster.port3}" />

</bean>

</set>

</property>

</bean>


  <bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">

<constructor-arg name="poolConfig" ref="jedisPoolConfig" />

<constructor-arg name="clusterConfig" ref="redisClusterConfiguration" />

</bean>


  <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">

<property name="connectionFactory" ref="jedisConnFactory"/>

<property name="keySerializer">

<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />

</property>

<property name="hashKeySerializer">

<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />

</property>

<property name="valueSerializer">

<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />

</property>

</bean>

<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">

<property name="connectionFactory" ref="jedisConnFactory" />

<property name="enableTransactionSupport" value="false" />

<property name="exposeConnection" value="true" />

<property name="keySerializer">

<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />

</property>

<property name="valueSerializer">

<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />

</property>

</bean>

</beans>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容