在开发中为了更好的管理数据,对redis进行了分组存储操作,在存值时加了命名空间来实现,如下:@Cacheable的value来实现分组
@Cacheable(value = "config",key ="#comparamid+'_'+#comCode" )/* */
@Query(value = "select * from test where comparamid=?1 and configcomcode=?2",nativeQuery = true)
public List <test> findByCondition(long comparamid,String comCode );
redis保存数据如下:

在批量获取数据时也需要加上namespace的前缀

因此在java后台批量删除时就可以用一下代码:
@Autowired
private RedisTemplate<String, ?> redisTemplate;
@RequestMapping(value = "/deal", method = RequestMethod.GET)
public Long delByPrefix(final String prefixKey){
//删除config::4开头的redis数据
Set<String> keys = redisTemplate.keys("config::4*");
if(!CollectionUtils.isEmpty(keys)) {
return redisTemplate.delete(keys);
}
return "SUCESS";
}
当然也可以利用客户端一件删除:

