1. 介绍
Spring Data Redis 简单说就是 spring 对 redis 操作的封装,其中 RedisTemplate 提供更加便捷的操作。
我们都知道,jedis的方法名其实就是一个个redis命令,但其实reids命令可以分成不同的组,
比如:字符串命令、List命令、Set命令等,
RedisTemplate 包含各种对redis的操作,并将不同数据类型的API,封装到不同的类中
![](https://img-blog.csdnimg.cn/img_convert/7f9c5c4c14848c76c29d99b1dd6085b7.png)
2. maven 依赖
创建一个spring boot 项目,添加以下依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
</parent>
<dependencies>
<!-- spring data 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>
<version>2.6.2</version>
</dependency>
<!-- spring boot 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
3. properties
spring.redis.host=192.168.56.103
spring.redis.port=6379
#lettuce 也是redis的客户端,spring boot 2.X,默认使用lettuce作为redis客户端