Browse Source

批量删除用户勋章

dev_shibei_match
wangchao 5 years ago
parent
commit
602d79547c
  1. 4
      epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserRedisKeys.java
  2. 25
      epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBadgeRedis.java

4
epmet-user/epmet-user-server/src/main/java/com/epmet/constant/UserRedisKeys.java

@ -1,5 +1,7 @@
package com.epmet.constant;
import org.apache.commons.lang3.StringUtils;
/**
* @Description
* @ClassName UserRedisKeys
@ -32,5 +34,5 @@ public class UserRedisKeys {
* @date 2020.11.05 13:34
*/
public static String getResiUserBadgeKey(String customerId,String userId){
return rootPrefix.concat("badge:user:").concat(customerId).concat(":").concat(userId);}
return rootPrefix.concat("badge:user:").concat(customerId).concat(":").concat( StringUtils.isBlank(userId) ? "*" : userId );}
}

25
epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBadgeRedis.java

@ -16,10 +16,13 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static com.epmet.commons.tools.redis.RedisUtils.MINUTE_THIRTY_EXPIRE;
@ -37,6 +40,8 @@ public class UserBadgeRedis {
private BadgeDao badgeDao;
@Autowired
private UserBadgeService badgeService;
@Autowired
private RedisTemplate redisTemplate;
/**
* @Description 获取客户徽章信息
@ -146,5 +151,25 @@ public class UserBadgeRedis {
return NumConstant.ONE;
}
/**
* @Description 批量清除用户徽章信息用处在客户取消点亮某个徽章后批量清除该客户下所有用户的徽章缓存当需要查取时再次初始化进缓存中
* @param customerId
* @return void
* @author wangc
* @date 2020.11.09 10:02
*/
public void batchClearUserBadgeCache(String customerId){
redisTemplate.executePipelined((RedisCallback<String>) connection ->{
Set<byte[]> keys =
connection.keys(redisTemplate.getKeySerializer().serialize(UserRedisKeys.getResiUserBadgeKey(customerId, null)));
if(!CollectionUtils.isEmpty(keys)){
keys.forEach( ser -> {connection.del(ser);});
}
return null;
});
}
}

Loading…
Cancel
Save