05【掌握】 SpringBoot 清空Redis所有缓存
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; } } /* ******************************************清理全部缓存结束************************************************** */ }
你的压力来源于无法自律,只是假装努力,现状跟不上内心欲望,所以你焦虑又恐慌。——杨不易
本文作者:杨不易呀
本文链接:https://www.cnblogs.com/yby6/p/13153046.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步