前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringMVC集成redis cluster集群模式

SpringMVC集成redis cluster集群模式

作者头像
stys35
发布2020-04-12 20:43:46
1.6K0
发布2020-04-12 20:43:46
举报
文章被收录于专栏:工作笔记精华工作笔记精华

1、cluster相对于哨兵模式是去中心化的,它的每个节点都存储了其它集群的信息,因此每个节点都可以做为集群的中心,容错能力强,具有更高的可用性和在线扩容能力。

2、简单的说,他就是将key通过hash算法,然后进行取模,将不同的key存储到对应的节点上,每个节点又可以有自己的从节点,也有一些局限性:

 mget,mset 命令不支持(客户端可能提供了兼容的操作方法,但不建议使用)

pipeline 管道操作去掉,改成单次操作

 watch,multi,exec 事务操作过程中,要保证只能对同一个key操作

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans" 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.xsd">
 
     <!-- jedis pool通用配置  -->
     <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
         <property name="maxTotal" value="${redis.maxTotal}" />
         <property name="maxIdle" value="${redis.maxIdle}" />
         <property name="minIdle" value="${redis.minIdle}" />
         <property name="maxWaitMillis" value="${redis.maxWait}" />
         <property name="testOnBorrow" value="${redis.testOnBorrow}" />
         <property name="testOnReturn" value="${redis.testOnReturn}" />
         <property name="testWhileIdle" value="${redis.testWhileIdle}" />
         <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />
     </bean>
 
     <bean id="mapPropertySource" class="org.springframework.core.env.MapPropertySource">
         <constructor-arg>
             <value type="java.lang.String">redis.propertis</value>
         </constructor-arg>
         <constructor-arg>
             <map>
                 <entry key="spring.redis.cluster.nodes" value="${spring.redis.cluster.nodes}"></entry>
                 <entry key="spring.redis.cluster.max-redirects" value="${spring.redis.cluster.max-redirects}"></entry>
             </map>
         </constructor-arg>
     </bean>
 
     <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
         <constructor-arg name="propertySource" ref="mapPropertySource" />
     </bean>
     <bean id="redisClusterConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
         <constructor-arg ref="redisClusterConfiguration" />
         <constructor-arg ref="jedisPoolConfig" />
         <property name="password" value="${spring.redis.cluster.password}" />
         <property name="timeout" value="${redis.timeout}" />
     </bean>
     <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
     <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
         <property name="connectionFactory" ref="redisClusterConnectionFactory" />
         <property name="keySerializer" ref="stringRedisSerializer" />
         <property name="valueSerializer" ref="stringRedisSerializer" />
     </bean>
 </beans>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档