您的位置:首页 > 数据库 > Redis

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>

还有一点,就是代码必须是

redisTemplate


如果是用Jedis,写的代码就苦B了,请把所有Jedis的相关代码改成Spring的redisTeplate

下面是好东东,redisTeplate常见API说明
http://www.cnblogs.com/yanan7890/p/6617305.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: