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

上一篇:地址:https://blog.csdn.net/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.csdn.net/download/qq_34077993/10750838

猜你喜欢

转载自blog.csdn.net/qq_34077993/article/details/83504925
今日推荐