美文网首页
Spring连接redis cluster的配置文件

Spring连接redis cluster的配置文件

作者: 赫灵 | 来源:发表于2018-11-09 09:38 被阅读0次

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

相关文章

网友评论

      本文标题:Spring连接redis cluster的配置文件

      本文链接:https://www.haomeiwen.com/subject/srsnxqtx.html