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 keys = stringRedisTemplate.keys("*");
    Iterator it1 = keys.iterator();
    while (it1.hasNext()) {
        stringRedisTemplate.delete(it1.next());
    }
	return R.ok("操作成功!");
}

你可能感兴趣的:(SpringBoot)