赞
踩
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> <version>3.16.6</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
yaml配置
#redis配置
redis:
dataBase: 0
password: XXXXXXXXXXXXX
host: XXXXXXXXXXXXX
port: XXXX
timeout: 10
pool:
max-wait: 100
max-idle: 10
Redis工具类封装
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import java.util.concurrent.TimeUnit; @Component public class RedisUtils { @Autowired private RedisTemplate<String, String> redisTemplate; /** * 读取缓存 * * @param key * @return */ public String get(final String key) { return redisTemplate.opsForValue().get(key); } /** * 写入缓存 */ public boolean set(final String key, String value) { boolean result = false; try { redisTemplate.opsForValue().set(key, value); result = true; } catch (E
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。