springboot整合redis jedis
时间: 2023-10-08 20:10:50 浏览: 75
可以提供一些相关的信息和代码示例。Spring Boot 提供了对 Redis 的自动配置,可以使用 Jedis 或 Lettuce 来操作 Redis。在 pom.xml 文件中添加 Redis 相关的依赖,然后在 application.properties 或 application.yml 文件中配置 Redis 的相关信息,即可在项目中使用 Redis。以下是一个示例:
pom.xml 文件中添加 Redis 相关的依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
```
application.properties 或 application.yml 文件中配置 Redis 的相关信息:
```properties
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123456
```
使用 Jedis 操作 Redis 的示例:
```java
@Autowired
private JedisPool jedisPool;
public void set(String key, String value) {
try (Jedis jedis = jedisPool.getResource()) {
jedis.set(key, value);
}
}
public String get(String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.get(key);
}
}
```
以上是一个简单的 springboot 整合 Redis Jedis 的示例,供参考。