004 SpringBoot 清空Redis所有缓存

SpringBoot 清空Redis所有缓存

1.前端

cleanRedis() {
  let that =this
  let url = '/epf-admin/admin/dictionaries/cleanRedis'
  this.$confirm('确定要清空redis缓存吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    that.$post(url,null).then(res => {
      if(res.code === 0){
        that.$message.success("清空成功!")
      }else{
        that.$message.error(res.msg)
      }
    })
  });    
},

2.后端

@Autowired
private StringRedisTemplate stringRedisTemplate;

@ApiIgnore
@RequestMapping("cleanRedis")
@ApiOperation(value="清空redis缓存", notes="")
public R cleanRedis() {
    Set<String> keys = stringRedisTemplate.keys("*");
    Iterator<String> it1 = keys.iterator();
    while (it1.hasNext()) {
        stringRedisTemplate.delete(it1.next());
    }
	return R.ok("操作成功!");
}
发布了125 篇原创文章 · 获赞 5 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/HuanFengZhiQiu/article/details/100543189
004