feature: 收藏功能.

This commit is contained in:
lijiahang
2023-09-01 17:52:00 +08:00
parent a4875154df
commit fb42e31f6e
2 changed files with 22 additions and 15 deletions

View File

@@ -34,26 +34,11 @@ public class RedisUtils {
* @return keys * @return keys
*/ */
public static Set<String> scanKeys(String match) { public static Set<String> scanKeys(String match) {
// TODO TEST
return scanKeys(ScanOptions.scanOptions() return scanKeys(ScanOptions.scanOptions()
.match(match) .match(match)
.build()); .build());
} }
/**
* 扫描 key
*
* @param match 匹配值
* @param count 数量
* @return keys
*/
public static Set<String> scanKeys(String match, int count) {
return scanKeys(ScanOptions.scanOptions()
.match(match)
.count(count)
.build());
}
/** /**
* 扫描 key * 扫描 key
* *

View File

@@ -94,15 +94,27 @@ public class FavoriteApiImpl implements FavoriteApi {
@Override @Override
@Async("asyncExecutor") @Async("asyncExecutor")
public void deleteFavoriteByUserId(Long userId) { public void deleteFavoriteByUserId(Long userId) {
if (userId == null) {
return;
}
// 删除缓存
List<String> favoriteKeyList = Arrays.stream(FavoriteTypeEnum.values()) List<String> favoriteKeyList = Arrays.stream(FavoriteTypeEnum.values())
.map(s -> FavoriteCacheKeyDefine.FAVORITE.format(s, userId)) .map(s -> FavoriteCacheKeyDefine.FAVORITE.format(s, userId))
.collect(Collectors.toList()); .collect(Collectors.toList());
redisTemplate.delete(favoriteKeyList); redisTemplate.delete(favoriteKeyList);
// 删除库
FavoriteQueryRequest request = new FavoriteQueryRequest();
request.setUserId(userId);
favoriteService.deleteFavorite(request);
} }
@Override @Override
@Async("asyncExecutor") @Async("asyncExecutor")
public void deleteFavoriteByUserIdList(List<Long> userIdList) { public void deleteFavoriteByUserIdList(List<Long> userIdList) {
if (Lists.isEmpty(userIdList)) {
return;
}
// 删除缓存
List<String> favoriteKeyList = new ArrayList<>(); List<String> favoriteKeyList = new ArrayList<>();
for (Long userId : userIdList) { for (Long userId : userIdList) {
Arrays.stream(FavoriteTypeEnum.values()) Arrays.stream(FavoriteTypeEnum.values())
@@ -110,11 +122,18 @@ public class FavoriteApiImpl implements FavoriteApi {
.forEach(favoriteKeyList::add); .forEach(favoriteKeyList::add);
} }
redisTemplate.delete(favoriteKeyList); redisTemplate.delete(favoriteKeyList);
// 删除库
FavoriteQueryRequest request = new FavoriteQueryRequest();
request.setUserIdList(userIdList);
favoriteService.deleteFavorite(request);
} }
@Override @Override
@Async("asyncExecutor") @Async("asyncExecutor")
public void deleteFavoriteByRelId(Long relId) { public void deleteFavoriteByRelId(Long relId) {
if (relId == null) {
return;
}
// 只删除数据库 redis 等自动失效 // 只删除数据库 redis 等自动失效
FavoriteQueryRequest request = new FavoriteQueryRequest(); FavoriteQueryRequest request = new FavoriteQueryRequest();
request.setRelId(relId); request.setRelId(relId);
@@ -123,6 +142,9 @@ public class FavoriteApiImpl implements FavoriteApi {
@Override @Override
public void deleteFavoriteByRelIdList(List<Long> relIdList) { public void deleteFavoriteByRelIdList(List<Long> relIdList) {
if (Lists.isEmpty(relIdList)) {
return;
}
// 只删除数据库 redis 等自动失效 // 只删除数据库 redis 等自动失效
FavoriteQueryRequest request = new FavoriteQueryRequest(); FavoriteQueryRequest request = new FavoriteQueryRequest();
request.setRelIdList(relIdList); request.setRelIdList(relIdList);