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所有缓存
基础教程推荐
猜你喜欢
- sql语句将数据库一条数据通过分隔符切割成多列方法实例 2023-07-29
- 六条比较有用的MySQL数据库操作的SQL语句小结 2023-12-11
- Python3.10动态修改Windows系统本地IP地址 2023-07-27
- PostgreSql JDBC事务操作方法详解 2023-07-21
- 解决Oracle 查询时报错ORA-00923: FROM keyword not found where expected的问题 2023-07-24
- Python实现获取照片的地理定位信息 2023-07-27
- windows下redis服务启动出现问题或者闪退 2023-09-13
- Ubuntu中Nginx的安装与配置详细说明 2023-12-30
- 数据库连接池以及sequelize实现增删改查等操作指 2022-08-31
- Oracle递归查询简单示例 2023-07-23
