package top.yangbuyi.system.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* description: 杨不易网站 :www.yangbuyi.top
* program: yangbuyi-erp-2020
* ClassName: ClearRedis
* create: 2020-04-24 15:37
*
* @author: yangbuyi
* @since: JDK1.8
**/
@RestController
@RequestMapping("clearRedis")
public class ClearRedisController {
@Autowired
private StringRedisTemplate stringRedisTemplate;
/* ******************************************清理全部缓存开始************************************************** */
@RequestMapping("cleanRedis")
public Map<String, Object> cleanRedis() {
Map<String, Object> map = new HashMap<>();
try {
// 获取所有key
Set<String> keys = stringRedisTemplate.keys("*");
assert keys != null;
// 迭代
Iterator<String> it1 = keys.iterator();
while (it1.hasNext()) {
// 循环删除
stringRedisTemplate.delete(it1.next());
}
map.put("code", 1);
map.put("msg", "清理全局缓存成功");
return map;
} catch (Exception e) {
map.put("code", -1);
map.put("msg", "清理全局缓存失败");
return map;
}
}
/* ******************************************清理全部缓存结束************************************************** */
}
package top.yangbuyi.system.controller; import org.springframework.beans.factory.annotation.Autowired; import
织梦狗教程
本文标题为:05【掌握】 SpringBoot 清空Redis所有缓存


基础教程推荐
猜你喜欢
- 基于Python创建可定制的HTTP服务器 2023-07-28
- mongodb数据库迁移变更的解决方案 2023-07-15
- Window环境下配置Mongodb数据库 2023-07-16
- redisTemplate封装jedis方法 2023-09-12
- SQL server数据库查询语句使用方法详细讲解 2024-01-10
- 几分钟教你掌握Redis简单动态字符串SDS 2023-07-12
- MongoDB固定集合使用方法详解(详细步骤) 2024-01-31
- 索引到底对查询速度有什么影响? 2024-01-31
- redis集群方案-一致性hash算法 2023-09-13
- SqlServer中批量update语句 2024-01-10