private void cacheToRedis(String key, List<String> list, int month) {
if (list == null || list.isEmpty()) {
return;
}
String tempKey = UUID.randomUUID().toString();
Boolean hasKey = stringRedisTemplate.hasKey(key);
if (hasKey != null && hasKey) {
stringRedisTemplate.rename(key, tempKey);
stringRedisTemplate.unlink(tempKey);
}
stringRedisTemplate.opsForSet().add(key, list.toArray(new String[0]));
Calendar instance = Calendar.getInstance();
instance.add(Calendar.MONTH, month);
stringRedisTemplate.expireAt(key, instance.getTime());
}
RedisTemplate 覆盖数据并异步删除
于 2022-11-09 17:49:36 首次发布