“Spring Boot 连 Redis 独立模式”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第63行: | 第63行: | ||
− | https://github.com/jihch/spring-boot-redis | + | https://github.com/jihch/spring-boot-redis-standalone |
2023年2月18日 (六) 04:53的最新版本
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
application.yml
spring:
redis:
database: 0
host: 127.0.0.1
port: 6379
password: vn4sj5kbxdaG
RedisTemplateTest.java
package io.github.jihch;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import javax.annotation.Resource;
@SpringBootTest
public class RedisTemplateTest {
@Resource
private RedisTemplate<String, Object> redisTemplate;
private static String KEY = "20230218";
private static String VALUE = "11:28:00";
@Test
public void testSet() {
redisTemplate.opsForValue().set(KEY, VALUE);
}
@Test
public void testGet() {
Object o = redisTemplate.opsForValue().get(KEY);
Assertions.assertEquals(VALUE, o);
}
}