目录
IDE:IDEA2020
JDK:JDK8
redis_version:3.2.100

(1)pom文件
- "1.0" encoding="UTF-8"?>
"http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
4.0.0 -
-
org.example -
01-springboot -
pom -
1.0-SNAPSHOT -
-
-
-
org.springframework.boot -
spring-boot-starter-parent -
2.1.8.RELEASE -
-
-
-
-
org.springframework.boot -
spring-boot-starter-data-redis -
-
-
org.springframework.boot -
spring-boot-starter-test -
test -
-
-
-
-
-
-
-
org.springframework.boot -
spring-boot-maven-plugin -
-
-
-
-
-
(2)测试代码
- package com.springboot.redis;
-
-
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.test.context.junit4.SpringRunner;
-
- @RunWith(SpringRunner.class)
- @SpringBootTest
-
-
- public class SpringbootRedisApplicationTests {
-
- @Autowired
- private RedisTemplate redisTemplate;
-
- @Test
- public void testSet(){
- //存入数据
- redisTemplate.boundValueOps("name").set("zhangsan");
- }
- @Test
- public void testGet(){
- //获取数据
- Object name = redisTemplate.boundValueOps("name").get();
- System.out.println(name);
- }
- }
(3)配置文件
- spring:
- redis:
- host: 127.0.0.1
- port: 6379
(4)引导类
- package com.springboot.redis;
-
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
-
- @SpringBootApplication
- public class SpringbootRedisApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(SpringbootRedisApplication.class, args);
- }
-
- }



链接:https://pan.baidu.com/s/1dhTVjf7_yIAn52tSMd72Sw
提取码:8xxi