springboot2.0x全系列一springboot2.0x集成Redis

上一篇:地址:https://blog.youkuaiyun.com/qq_34077993/article/details/83417464

springboot集成redis非常的方便

首先在pom文件中引进依赖:

<!-- Spring Boot Redis依赖开始 -->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--spring2.0集成redis所需common-pool2-->
<dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-pool2</artifactId>
   <version>2.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
   <groupId>redis.clients</groupId>
   <artifactId>jedis</artifactId>
   <version>2.9.0</version>
</dependency>
<!-- Spring Boot Redis依赖结束 -->

每个依赖的作用可以自行百度

然后配置redis连接所需的一些必要信息

我这里使用的是

application-redis.yml文件

来看下文件内容

每个栏目的作用我都进行了标注

下面进行测试:

为什么使用

StringRedisTemplate而不是用
RedisTemplate;

因为直接使用RedisTemplate会导致存入redis中的key完全不可读

补充:

redis的nameSpace

以:作为风格,最后在redis中存入值的效果类似于group 分组

如图

项目地址:https://download.youkuaiyun.com/download/qq_34077993/10750838

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值