redis批量删除key

    //用户存放验证码
    public static final String USER_INFO_CAPTCHA_CODE = "userinfo:captcha_code:"; 
  
    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * redis批量删除key
     */
    @Test
    public void redisTest() {
        List<String> userIds = new ArrayList<>();
        userIds.add("admin");
        userIds.add("test1");
        userIds.add("test2");
        List<String> delKeys = userIds.stream().map(v -> Const.USER_INFO_CAPTCHA_CODE + v).collect(Collectors.toList());
        redisTemplate.delete(delKeys);
    }

posted @ 2022-09-26 14:01  难忘是想起  阅读(0)  评论(0)    收藏  举报  来源