欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > Redis---10---SpringBoot集成Redis

Redis---10---SpringBoot集成Redis

2024/10/24 6:27:58 来源:https://blog.csdn.net/m0_51045361/article/details/140171832  浏览:    关键词:Redis---10---SpringBoot集成Redis

SpringBoot集成Redis

总体概述jedis-lettuce-RedisTemplate三者的联系

本地Java连接Redis常见问题,注意

	bind配置请注释掉​	保护模式设置为no​	Linux系统的防火墙设置​	redis服务器的IP地址和密码是否正确​	忘记写访问redis的服务端口号和auth密码

集成Jedis

是什么

Jedis Client是Redis官网推荐的一个面向Java客户端,库文件实现了对各类API进行封装调用。

步骤

建Module
改POM
写YML
主启动
业务类

集成lettuce

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

集成RedisTemplate-推荐使用

连接单机

boot整合redis基础演示

建Module
改POM
写YML
主启动
业务类

改POM

<!--SpringBoot与Redis整合依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId></dependency>

写yaml

server.port=7777spring.application.name=redis7_study# ========================logging=====================
logging.level.root=info
logging.level.com.atguigu.redis7=info
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger- %msg%n logging.file.name=D:/mylogs2023/redis7_study.log
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger- %msg%n# ========================swagger=====================
spring.swagger2.enabled=true
#在springboot2.6.X结合swagger2.9.X会提示documentationPluginsBootstrapper空指针异常,
#原因是在springboot2.6.X中将SpringMVC默认路径匹配策略从AntPathMatcher更改为PathPatternParser,
# 导致出错,解决办法是matching-strategy切换回之前ant_path_matcher
spring.mvc.pathmatch.matching-strategy=ant_path_matcher# ========================redis单机=====================
spring.redis.database=0
# 修改为自己真实IP
spring.redis.host=192.168.111.185
spring.redis.port=6379
spring.redis.password=111111
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.min-idle=0

连接集群

.max-wait=-1ms
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.min-idle=0

### 连接集群

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com