标签:缓存 value code str autowired 工具类 one private ram
import org.springframework.beans.factory.annotation.Autowired;@Component
public class RedisUtil {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
public void set(String key, String value) {
stringRedisTemplate.opsForValue().set(key, value);
}
public void set(String key, String value, long time) {
stringRedisTemplate.opsForValue().set(key, value, time);
}
public void set(String key, String value, long time, TimeUnit unit) {
// 向redis里存入数据和设置缓存时间
stringRedisTemplate.opsForValue().set(key, value, time, unit);
}
public String get(String key) {
return stringRedisTemplate.opsForValue().get(key);
}
public Set<String> getKeys(String pattern) {
return stringRedisTemplate.keys(pattern);
}
public void delete(String key) {
stringRedisTemplate.delete(key);
}
标签:缓存 value code str autowired 工具类 one private ram
原文地址:https://blog.51cto.com/7218743/2544681