JDK|Redis
小于 1 分钟
描述
Redis基本使用
1. 引入依赖
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. 配置redis
#application.yml
spring:
data:
redis:
host: 127.0.0.1
port: 6379
password: 123456
3. 下载Redis客户端和服务端
4.基本使用
@SpringBootTest
public class redisTest {
@Resource
private RedisTemplate redisTemplate;
@Test
public void testSet(){
ValueOperations<String, String> ops = redisTemplate.opsForValue();
ops.set("50","6666",15, TimeUnit.SECONDS);
}
@Test
public void testGet(){
ValueOperations<String, String> ops = redisTemplate.opsForValue();
System.out.println(ops.get("50"));
}
}