SpringBoot整合redis(lettuce)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
server:
port: 8823
spring:
redis:
host: 127.0.0.1
port: 6379
password: 123456
timeout: 3000
datasource:
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/hellomybatis?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
mybatis:
type-aliases-package: com.example.batis.entity
mapper-locations:
- classpath:mybatis/mapper/*.xml
package com.example.batis;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import java.sql.SQLException;
@SpringBootTest
class BatisApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
@Test
void contextLoads() throws SQLException {
·······
redisTemplate.opsForValue().set("key","value");
RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
connection.flushDb();
connection.flushAll();
}
}
- 关闭redis的时候要用redis-cli.exe shutdown,暴力关闭redis数据会丢失
共有条评论 网友评论