缓存改成全使用string模式

This commit is contained in:
zhongzb
2023-04-24 22:59:16 +08:00
parent 0d2ba4e70a
commit 1c58a17cbc
4 changed files with 27 additions and 7 deletions

View File

@@ -92,7 +92,7 @@ public class UserCache {
public Map<Long, User> getUserInfoBatch(Set<Long> uids) {
List<String> keys = uids.stream().map(a -> RedisKey.getKey(RedisKey.USER_INFO_STRING, a)).collect(Collectors.toList());
List<User> mget = redisUtils.mget(keys, User.class);
Map<Long, User> map = mget.stream().collect(Collectors.toMap(User::getId, Function.identity()));
Map<Long, User> map = mget.stream().filter(Objects::nonNull).collect(Collectors.toMap(User::getId, Function.identity()));
//还需要load更新的uid
List<Long> needLoadUidList = uids.stream().filter(a -> !map.containsKey(a)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(needLoadUidList)) {

View File

@@ -34,7 +34,7 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
@Override
@RedissonLock(key = "#uid")
public void acquireItem(Long uid, Long itemId, IdempotentEnum idempotentEnum, String businessId) {//todo 分布式锁
public void acquireItem(Long uid, Long itemId, IdempotentEnum idempotentEnum, String businessId) {
String idempotent = getIdempotent(itemId, idempotentEnum, businessId);
UserBackpack userBackpack = userBackpackDao.getByIdp(idempotent);
//幂等检查