【笔记】SpringBoot项目整合Jedis

前言

SpringBoot项目整合Jedis,实现操作Redis

引入依赖

pom.xml
1
2
3
4
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>

创建配置文件

redis.properties
1
2
redis.host=127.0.0.1
redis.port=6379

创建配置类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Configuration
@PropertySource("classpath:/properties/redis.properties")
public class RedisConfig {

@Value("${redis.host}")
private String host;
@Value("${redis.port}")
private Integer port;

@Bean
public Jedis jedis(){
return new Jedis(host, port);
}

}

完成