spring redis sentinel deployment

Introduction:

        Implement reids master slave mode to add sentinel monitoring, when the host goes down, the backup machine assumes the host identity for production work.

 

Implementation:

       1. First follow the spring redis integration http://see-you-again.iteye.com/admin/blogs/2323435 to complete the configuration in non-sentry monitoring mode.

       2. Modify the pom file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!--suppress ALL -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       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">

    <context:property-placeholder location="classpath:redis.properties" />

    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"
          p:maxIdle="${redis.maxIdle}"
          p:maxTotal="${redis.maxActive}"
          p:maxWaitMillis="${redis.maxWait}"
          p:testOnBorrow="${redis.testOnBorrow}">
    </bean>
    <!-- do not use sentry
        <bean id="jedisConnFactory"
              class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
              p:usePool="true"
              p:hostName="127.0.0.1"
              p:port="7000"
              p:timeout="200"
              p:password=""
              p:poolConfig-ref="poolConfig"/>
         -->
        <bean id="jedisConnFactory"
              class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
            <constructor-arg name="sentinelConfig" ref="redisSentinelConfiguration"></constructor-arg>
            <constructor-arg name="poolConfig" ref="poolConfig"></constructor-arg>
        </bean>

    <bean id="redisSentinelConfiguration"
          class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
        <property name="master">
            <bean class="org.springframework.data.redis.connection.RedisNode">
                <property name="name" value="mymaster"></property>
            </bean>
        </property>
        <property name="sentinels">
            <set>
                <!-- Note that the sentinel information is configured here, not the redis service information-->
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg index="0" value="127.0.0.1" />
                    <constructor-arg index="1" value="5001" />
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg index="0" value="127.0.0.1" />
                    <constructor-arg index="1" value="5002" />
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg index="0" value="127.0.0.1" />
                    <constructor-arg index="1" value="5003" />
                </bean>               
            </set>
        </property>
    </bean>

    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate" >
        <property name="connectionFactory" 	ref="jedisConnFactory" />
        <property name="enableTransactionSupport" value="true" />
    </bean>

    <bean id="userDao" class="com.test.redis.UserDao" >
        <constructor-arg name="redisTemplate" ref="redisTemplate"/>
    </bean>

    <bean id="redisDao" class="com.test.redis.RedisDao" >
        <constructor-arg name="redisTemplate" ref="redisTemplate"/>
    </bean>
</beans>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327064666&siteId=291194637