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呢?
使用通过上述的参数表格, JedisPoolConfig 可以使用,但是没有 JedisSentinelPool参数
而 JedisShardInfo属性并不是list,只是 包含了jedis服务器的一些信息 ,咋整? 这时候,我们来看看 JedisConnectionFactory 构造函数: 可以看出 ,构造函数支持 RedisSentinelConfiguration 或者 RedisClusterConfiguration
|