SpringBoot2.7.14整合redis7的详细过程
作者:LSCBAiotAigc
这篇文章主要介绍了SpringBoot2.7.14整合redis7的详细过程,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
需要的依赖库:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <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>
单节点整合SpringBoot:
spring: redis: database: 0 host: 192.168.56.201 port: 6379 username: xxxxxx password: XXXXXXXXX
Student.java:
package com.lscbaiotaigc.entiies; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.Date; @Data @AllArgsConstructor @NoArgsConstructor public class Student implements Serializable { private String id; private String name; private int age; private Date birthday; }
StudentController.java:
package com.lscbaiotaigc.controller; import com.lscbaiotaigc.entities.Student; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; @RestController public class StudentController { @Resource private RedisTemplate redisTemplate; @PostMapping("/setStudent") public String setStudent(@RequestBody Student student){ redisTemplate.opsForValue().set("student1", student); return "SUCCESS"; } }
到此这篇关于SpringBoot2.7.14整合redis7的文章就介绍到这了,更多相关SpringBoot2.7.14整合redis7内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!