springboot2.x 整合redis集群的几种方式
一、不指定redis连接池
#系统默认连接池
yml配置文件:
spring:
redis:
cluster:
nodes:
- 192.168.1.236:7001
- 192.168.1.236:7002
- 192.168.1.236:7003
- 192.168.1.244:7004
- 192.168.1.244:7005
- 192.168.1.244:7006
max-redirects: 3 # 获取失败 最大重定向次数
pool:
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
min-idle: 5 # 连接池中的最小空闲连接
timeout: 6000 # 连接超时时长(毫秒)
这种方式 redisTemplate 可直接使用默认,
在使用的地方直接注入即可
@Autowired
private RedisTemplate<String, Object> redisTemplate;
二、使用jedis连接池
# 使用jedis连接池
yml配置文件:
spring:
redis:
password: # 密码(默认为空)
timeout: 6000ms # 连接超时时长(毫秒)
cluster:
nodes:
- 192.168.1.236:7001
- 192.168.1.236:7002
- 192.168.1.236:7003
- 192.168.1.244:7004
- 192.168.1.244:7005
- 192.168.1.244:7006
jedis:
pool:
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
min-idle: 5 # 连接池中的最小空闲连接
//连接池注入配置信息
@Configuration
public class RedisConfig {
@Autowired
private RedisConnectionFactory factory; @Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(factory);
return redisTemplate;
}
}
在使用的地方直接注入即可
@Autowired
private RedisTemplate<String, Object> redisTemplate;
三、使用lettuce连接池(推荐)
# 使用lettuce连接池
yml配置文件:
spring:
redis:
timeout: 6000ms
password:
cluster:
max-redirects: 3 # 获取失败 最大重定向次数
nodes:
- 192.168.1.236:7001
- 192.168.1.236:7002
- 192.168.1.236:7003
- 192.168.1.244:7004
- 192.168.1.244:7005
- 192.168.1.244:7006
lettuce:
pool:
max-active: 1000 #连接池最大连接数(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
min-idle: 5 # 连接池中的最小空闲连接
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
//连接池注入配置信息
@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setConnectionFactory(redisConnectionFactory);
return template;
}
}
在使用的地方直接注入即可
@Autowired
private RedisTemplate<String, Object> redisTemplate;
---------------------
作者:qq_31256487
来源:CSDN
原文:https://blog.csdn.net/qq_31256487/article/details/83144088
版权声明:本文为博主原创文章,转载请附上博文链接!
springboot2.x 整合redis集群的几种方式的更多相关文章
- SpringBoot2.0 整合 Redis集群 ,实现消息队列场景
本文源码:GitHub·点这里 || GitEE·点这里 一.Redis集群简介 1.RedisCluster概念 Redis的分布式解决方案,在3.0版本后推出的方案,有效地解决了Redis分布式的 ...
- redis集群的三种方式
Redis三种集群方式:主从复制,哨兵模式,Cluster集群. 主从复制 基本原理 当新建立一个从服务器时,从服务器将向主服务器发送SYNC命令,接收到SYNC命令后的主服务器会进行一次BGSAVE ...
- 测试redis集群的两种方式:分片和哨兵
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; i ...
- Springboot2.x集成Redis集群模式
Springboot2.x集成Redis集群模式 说明 Redis集群模式是Redis高可用方案的一种实现方式,通过集群模式可以实现Redis数据多处存储,以及自动的故障转移.如果想了解更多集群模式的 ...
- SpringBoot整合Redis集群
一.环境搭建 Redis集群环境搭建:https://www.cnblogs.com/zwcry/p/9174233.html 二.Spring整合Redis集群 1.pom.xml <proj ...
- (七)整合 Redis集群 ,实现消息队列场景
整合 Redis集群 ,实现消息队列场景 1.Redis集群简介 1.1 RedisCluster概念 2.SpringBoot整合Redis集群 2.1 核心依赖 2.2 核心配置 2.3 参数渲染 ...
- 05.haproxy+mysql负载均衡 整合 redis集群+ssm
本篇重点讲解haproxy+mysql负载均衡,搭建完成后与之前搭建的redis+ssm进行整合 (注:这里用到了两台mysql数据库,分别安装两台虚拟机上,已经成功实现主主复制,如果有需要,请查看我 ...
- Springboot2.0访问Redis集群
Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作高性能的key-value数据库.缓存和消息中间件,掌握它是程序员的必备技能,下面是一个springboot访问redis的 ...
- Redis(七)-- SpringMVC整合Redis集群
1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...
随机推荐
- ACM的一点基础知识
所摘内容来自于XJTU小学期ACM培训PPT log 默认以2为底 计算机一秒可以看作1e8次 保证数据计算精度及数据所需必要大小 a=1LL*a*a%p//在计算时通过乘以1LL,临时将Int转化为 ...
- 关于redis的几件小事(二)redis线程模型
1.memcached和redis有什么区别? (1)Redis支持服务器端的数据操作 redis和memcached相比,redis拥有更多的 数据结构并且支持更丰富的数据操作 ,通常在memcac ...
- CSS-百分百布局
1.照片随着大小变化: 这里面重点就是每个包裹盒子是25%,图片是100%显示: <div class="box2"> <p> //这里都是4个: < ...
- C# 之 String.Empty
.NET Framework 类库,表示空字符串,此字段为只读,命名空间:System.程序集:mscorlib(在 mscorlib.dll 中). EG:protected string lo ...
- 转载:开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
转自:https://www.cnblogs.com/findumars/p/6309048.html 首先借用有心人士的一张相当直观清晰的图来划分各种协议:开源许可证GPL.BSD.MIT.Mozi ...
- java常用的加密技术
详见:https://blog.csdn.net/it_beecoder/article/details/71480770 Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以 ...
- springboot(1)-基础篇
什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...
- Linux内核管理子系统和进程管理子系统
内核管理子系统职能:1.管理虚拟地址与物理地址的映射 2.物理内存的分配 程序:存放在磁盘上的一系列代码和数据的可执行映像,是一个静止的实体. 进程:是一个执行中的程序,它是动态的实体 进程四要素: ...
- tp5实现Redis的简单使用
方法1: Controller <?php namespace app\index\controller; use think\Controller; use think\session\dri ...
- cgicc使用
CgiCc 使用 一.下载 下载地址: http://ftp.gnu.org/gnu/cgicc/ ftp://ftp.gnu.org/gnu/cgicc/ 二.配置.编译.安装 下载完成后解压:sh ...