redis 哨兵 配置spring
2017-04-29 11:58
417 查看
公司redis开始配置的单台redis地址连接的,
现在要改成通过哨兵配置,本人以前没搞过redsi啊,但楼主爱学,马上网上查查,哨兵是什么神,
原来就像zookeeper类似,监控服务的,如果一个redis挂了,兵哥,就会故障转移。
高可用方案,就这么产生了。
下面spring配置信息,我也是copy的网上的改改。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="2048" />
<property name="maxIdle" value="200" />
<property name="numTestsPerEvictionRun" value="1024" />
<property name="timeBetweenEvictionRunsMillis" value="30000" />
<property name="minEvictableIdleTimeMillis" value="-1" />
<property name="softMinEvictableIdleTimeMillis" value="10000" />
<property name="maxWaitMillis" value="1500" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="testOnReturn" value="false" />
<property name="jmxEnabled" value="true" />
<property name="blockWhenExhausted" value="false" />
</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="xxx-test-master">
</property>
</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="xx.xx.xxx.xxx" />
<constructor-arg name="port" value="26379" />
</bean>
</set>
</property>
</bean>
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:password="xxxxxxx"><!--密码拉 -->
<constructor-arg name="sentinelConfig" ref="redisSentinelConfiguration"></constructor-arg>
<constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
</bean>
<bean id="redisTemplates" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>
</beans>
还有一点,就是代码必须是
如果是用Jedis,写的代码就苦B了,请把所有Jedis的相关代码改成Spring的redisTeplate
下面是好东东,redisTeplate常见API说明
http://www.cnblogs.com/yanan7890/p/6617305.html
现在要改成通过哨兵配置,本人以前没搞过redsi啊,但楼主爱学,马上网上查查,哨兵是什么神,
原来就像zookeeper类似,监控服务的,如果一个redis挂了,兵哥,就会故障转移。
高可用方案,就这么产生了。
下面spring配置信息,我也是copy的网上的改改。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="2048" />
<property name="maxIdle" value="200" />
<property name="numTestsPerEvictionRun" value="1024" />
<property name="timeBetweenEvictionRunsMillis" value="30000" />
<property name="minEvictableIdleTimeMillis" value="-1" />
<property name="softMinEvictableIdleTimeMillis" value="10000" />
<property name="maxWaitMillis" value="1500" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="testOnReturn" value="false" />
<property name="jmxEnabled" value="true" />
<property name="blockWhenExhausted" value="false" />
</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="xxx-test-master">
</property>
</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="xx.xx.xxx.xxx" />
<constructor-arg name="port" value="26379" />
</bean>
</set>
</property>
</bean>
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:password="xxxxxxx"><!--密码拉 -->
<constructor-arg name="sentinelConfig" ref="redisSentinelConfiguration"></constructor-arg>
<constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
</bean>
<bean id="redisTemplates" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>
</beans>
还有一点,就是代码必须是
redisTemplate
如果是用Jedis,写的代码就苦B了,请把所有Jedis的相关代码改成Spring的redisTeplate
下面是好东东,redisTeplate常见API说明
http://www.cnblogs.com/yanan7890/p/6617305.html
相关文章推荐
- redis哨兵模式spring配置
- spring-data-redis使用哨兵配置一主多从
- spring-data-redis使用哨兵配置一主多从
- spring-data-redis 哨兵配置例子
- redis 哨兵模式配置 和 spring data redis 哨兵配置 总结
- spring-data-redis配置详解
- 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)
- jedis-2.4.2 和 spring-data-redis-1.2.0.RELEASE 配置
- SPRING DATA - REDIS配置
- 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)
- Spring MVC +Mybatis + Maven 配置之Redis配置
- shiro+redis+springMvc整合配置及说明
- 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)
- SpringMVC + MyBatis + Mysql + Redis(作为二级缓存) 配置
- spring 使用redis集群配置
- Spring boot 手动配置redis
- 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)
- spring-data-redis + Jedis配置文件
- spring redisTemplate 配置
- 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)