SpringBoot整合Redis

2023/11/19 javaSpringBootredis

# SpringBoot整合Redis

# 选择依赖

注意的点不多,直接附代码

在SpringBoot构造器选项里找到NoSql

然后选Spring Data Redis (Access+Driver)

image-20231010192645670

# 配置文件

spring:
  redis:
    password: ****
    port: 6379
    host: localhost
1
2
3
4
5

# 测试类

@SpringBootTest
class SpringbootRedisApplicationTests {
    @Autowired
    private RedisTemplate redisTemplate;
    @Test
    void setTest(){
        redisTemplate.boundValueOps("name").set("zhangsan");
    }
    @Test
    void getTest(){
        Object name = redisTemplate.boundValueOps("name").get();
        System.out.println(name);

    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
最后更新于: 2024/2/27 17:14:39