• springdataRedis连接redis集群


    配置文件:

    <?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: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 ignore-unresolvable="true" location="classpath:properties/redis-cluster-config.properties" />  
        <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">  
            <property name="maxRedirects" value="${redis.maxRedirects}"></property>  
            <property name="clusterNodes">  
                <set>  
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">  
                        <constructor-arg name="host" value="${redis.host1}"></constructor-arg>  
                        <constructor-arg name="port" value="${redis.port1}"></constructor-arg>  
                    </bean>  
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">  
                        <constructor-arg name="host" value="${redis.host2}"></constructor-arg>  
                        <constructor-arg name="port" value="${redis.port2}"></constructor-arg>  
                    </bean>  
                        <bean class="org.springframework.data.redis.connection.RedisClusterNode">  
                        <constructor-arg name="host" value="${redis.host3}"></constructor-arg>  
                        <constructor-arg name="port" value="${redis.port3}"></constructor-arg>  
                    </bean>  
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">  
                        <constructor-arg name="host" value="${redis.host4}"></constructor-arg>  
                        <constructor-arg name="port" value="${redis.port4}"></constructor-arg>  
                    </bean>  
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">  
                        <constructor-arg name="host" value="${redis.host5}"></constructor-arg>  
                        <constructor-arg name="port" value="${redis.port5}"></constructor-arg>  
                    </bean>  
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">  
                        <constructor-arg name="host" value="${redis.host6}"></constructor-arg>  
                        <constructor-arg name="port" value="${redis.port6}"></constructor-arg>  
                    </bean>  
                </set>  
            </property>  
        </bean>  
        <bean id="jedisPoolConfig"   class="redis.clients.jedis.JedisPoolConfig">  
                <property name="maxIdle" value="${redis.maxIdle}" />   
                <property name="maxTotal" value="${redis.maxTotal}" />   
        </bean>  
        <bean id="jeidsConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"  >  
            <constructor-arg ref="redisClusterConfiguration" />  
            <constructor-arg ref="jedisPoolConfig" />  
        </bean>    
        <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">  
            <property name="connectionFactory" ref="jeidsConnectionFactory" />  
        </bean>  
    </beans>

    redis-cluster-config.properties:

    #cluster configuration
    redis.host1=192.168.230.133
    redis.port1=7001
    
    redis.host2=192.168.230.133
    redis.port2=7002
    
    redis.host3=192.168.230.133
    redis.port3=7003
    
    redis.host4=192.168.230.133
    redis.port4=7004
    
    redis.host5=192.168.230.133
    redis.port5=7005
    
    redis.host6=192.168.230.133
    redis.port6=7006
    
    redis.maxRedirects=3
    redis.maxIdle=100
    redis.maxTotal=600

    开发中并不需要注意这些内容,只是需要注意开发逻辑即可

  • 相关阅读:
    nodejs学习(一)--express+ejs生成项目
    react-native React Native version mismatch
    qrcode length overflow 生成二维码网址长度溢出解决办法
    禁止input输入空格
    微信开发:清除微信浏览器缓存
    多行文本溢出显示...的方法(-webkit-line-clamp)
    angular路由(自带路由篇)
    angular入门(基础篇)
    Python文件读写(open(),close(),with open() as f...)
    centos6.9使用yum安装mysql(简单粗暴,亲测有效)
  • 原文地址:https://www.cnblogs.com/xiufengchen/p/10371682.html
Copyright © 2020-2023  润新知