最近一直在使用Redis作为缓存数据库,在使用当中,刚开始没有注意配置问题。

1、纯粹的注入单机模式

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="1" />
<property name="maxTotal" value="5" />
<property name="blockWhenExhausted" value="true" />
<property name="maxWaitMillis" value="30000" />
<property name="testOnBorrow" value="true" />
</bean> <bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="此处填写redis-host" />
<property name="port" value="此处填写redis-port" />
<property name="database" value="1" />
<property name="poolConfig" ref="jedisPoolConfig" />
<property name="usePool" value="true" />
<property name="timeout" value="10000"></property>
</bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean> <alias name="redisTemplate" alias="cacheRedisTemplate"/>
<alias name="redisTemplate" alias="transportRedisTemplate"/> <!-- 使用StringRedisTemplate配置 -->
<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>

2、Redis集群模式,集群模式又分为两种,哨兵模式实现 RedisClusterConfiguration实现,配置如下

    <bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<constructor-arg index="0"> <!-- 哨兵模式:RedisSentinelConfiguration,也是可以支持集群
<bean class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
<constructor-arg>
<set>
<value>www.baidu.com:26379</value>
<value>www.cnblogs.com:26479</value>
</set>
</bean>
--> <!-- RedisClusterConfiguration, -->
<bean class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<constructor-arg>
<list>
<value>127.0.0.1:8001</value>
<value>127.0.0.2:8002</value>
<value>127.0.0.3:8003</value>
<value>127.0.0.4:8004</value>
<value>127.0.0.5:8005</value>
<value>127.0.0.6:8006</value>
</list>
</constructor-arg>
<property name="maxRedirects" value="5" />
</bean> </constructor-arg>
<constructor-arg index="1">
<bean class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="100"/>
<property name="maxIdle" value="10"/>
<property name="minIdle" value="1"/>
<property name="maxWaitMillis" value="30000"/>
</bean>
</constructor-arg>
</bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean> <alias name="redisTemplate" alias="cacheRedisTemplate"/> <alias name="redisTemplate" alias="transportRedisTemplate"/> <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>

哨兵模式主要是监听、检测 master 的状态,如果监听到状态异常,则使用M-S进行切换,将其中的Slave作为master,将master(异常)作为Slave,转换之后相对应的配置文件也会随着改变;

其他相关参考:

https://blog.csdn.net/donggang1992/article/details/50981341

https://blog.csdn.net/zhousenshan/article/details/51822253

最新文章

  1. KnockoutJS 3.X API 第四章 数据绑定(2) 控制流foreach绑定
  2. [Android]使用AdapterTypeRender对不同类型的item数据到UI的渲染
  3. METEOR 及ANGULARJS
  4. checkbox全选功能
  5. Hive(四):c#通过odbc访问hive
  6. UVa 297 - Quadtrees
  7. CentOS安装卸载memcache及JAVA示例
  8. hdu1272并查集入门
  9. Twenty Newsgroups Classification实例任务之TrainNaiveBayesJob(一)
  10. 如何用70行Java代码实现深度神经网络算法
  11. kafka环境
  12. el 表达式遍历Map
  13. 201521123108 《Java程序设计》第13周学习总结
  14. Traefik实现Kubernetes集群服务外部https访问
  15. 微服务(Microservices)和服务网格(Service Mesh)架构概念整理
  16. Android平台上的Aplay与TinyAlsa移植使用
  17. Go语言之进阶篇服务器如何知道用户需要什么资源
  18. AI-Info-Micron:用内存解决方案演化神经网络智能
  19. Openwrt 移植hello world
  20. codeforce 977 F. Consecutive Subsequence

热门文章

  1. 微服务架构的服务与发现-Spring Cloud
  2. SFTP工具类
  3. apache 压力测试ab
  4. EasyPopup
  5. LVS &amp; NGINX
  6. python调用shell脚本时需要切换目录
  7. BCP文件导入SQLServer数据库遇到的问题
  8. 如何用AJax提交name[]数组?
  9. CentOS7安装Go环境
  10. 禅道docker化(Centos7.2)