redis集羣配置

1. 咱們原來的 redis data 配置

1.1. spring-redis.xml

<?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:loxia="http://loxia.benjamin.cn/schema/core"
        xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
        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://loxia.benjamin.cn/schema/core http://loxia.benjamin.cn/schema/core/loxia-spring-ext.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd   
            ">

        <bean id="redisconfig" class="redis.clients.jedis.JedisPoolConfig">
            <property  name="maxActive" >
                <value type="long">#{redis['redis.MaxActive']}</value>
            </property>
            <property  name="maxIdle" >
                <value type="long">#{redis['redis.MaxIdle']}</value>
            </property>
            <property  name="maxWait">
                <value type="long">#{redis['redis.MaxWait']}</value>
            </property>
            <property  name="testOnBorrow" >
                <value type="boolean">true</value>
            </property>
            <property  name="testOnReturn" >
                <value type="boolean">true</value>
            </property>
        </bean>

        <bean id="jedisSentinelPool" class="redis.clients.jedis.JedisSentinelPool">
            <constructor-arg ref="redisconfig"></constructor-arg>

            <constructor-arg type="java.util.Set">
                <set>
                    <value>#{redis['redis.sentinel1']}</value>
                    <value>#{redis['redis.sentinel2']}</value>
                    <value>#{redis['redis.sentinel3']}</value>
                </set>

            </constructor-arg>

            <constructor-arg >
                <value>#{redis['redis.mastername']}</value>
            </constructor-arg>

        </bean>
    </beans>

1.2 redis.properties下載

#A string containing whitespace or comma separated host or IP addresses and port numbers of the form "host:port host2:port" or "host:port, host2:port".
    redis.sentinel1=redis01.public.test.baozun.cn:26379
    redis.sentinel2=redis02.public.test.baozun.cn:26379
    redis.sentinel3=redis03.public.test.baozun.cn:26379

    redis.mastername=testenv

    redis.timeout=1000
    redis.MaxActive=50
    redis.MaxIdle=60000
    redis.MaxWait=5000

    ##這個是咱們自定義的 key前綴, 以便用同一套redis集羣,適應多個不一樣的商城
    redis.keystart=feilongdev

2.redis 集羣配置

下載

那麼咱們怎麼使用上面的環境來配置咱們的spring-session呢?java

使用經過上述的參數表格, JedisPoolConfig 能夠使用,可是沒有 JedisSentinelPool參數git

而 JedisShardInfo屬性並非list,只是 包含了jedis服務器的一些信息 ,咋整?github

這時候,咱們來看看 JedisConnectionFactory 構造函數:redis

能夠看出 ,構造函數支持 RedisSentinelConfiguration 或者 RedisClusterConfigurationspring

相關文章
相關標籤/搜索