|
@@ -82,21 +82,23 @@ public class ViewedStrategy implements FilterStrategy {
|
|
|
for (int i = list.size() - 1; i >= 0 && limit-- > 0; i--) {
|
|
|
viewedVideoIds.add(String.valueOf(list.get(i).getVideoId()));
|
|
|
}
|
|
|
-
|
|
|
- // 异步写Redis
|
|
|
- ThreadPoolFactory.defaultPool().execute(() -> {
|
|
|
- redisTemplate.executePipelined(new SessionCallback<String>() {
|
|
|
- @Override
|
|
|
- public <A, B> String execute(RedisOperations<A, B> redisOperations) throws DataAccessException {
|
|
|
- SetOperations<String, String> operations =
|
|
|
- (SetOperations<String, String>) redisOperations.opsForSet();
|
|
|
- operations.add(key, viewedVideoIds.toArray(new String[viewedVideoIds.size()]));
|
|
|
- redisTemplate.expire(key, 360 * 3600, TimeUnit.SECONDS);
|
|
|
- return null;
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ // 避免穿透
|
|
|
+ viewedVideoIds.add("-1");
|
|
|
}
|
|
|
+ // 异步写Redis
|
|
|
+ ThreadPoolFactory.defaultPool().execute(() -> {
|
|
|
+ redisTemplate.executePipelined(new SessionCallback<String>() {
|
|
|
+ @Override
|
|
|
+ public <A, B> String execute(RedisOperations<A, B> redisOperations) throws DataAccessException {
|
|
|
+ SetOperations<String, String> operations =
|
|
|
+ (SetOperations<String, String>) redisOperations.opsForSet();
|
|
|
+ operations.add(key, viewedVideoIds.toArray(new String[viewedVideoIds.size()]));
|
|
|
+ redisTemplate.expire(key, 360 * 3600, TimeUnit.SECONDS);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(viewedVideoIds)) {
|
|
@@ -140,21 +142,23 @@ public class ViewedStrategy implements FilterStrategy {
|
|
|
for (int i = list.size() - 1; i >= 0 && limit-- > 0; i--) {
|
|
|
viewedVideoIds.add(String.valueOf(list.get(i).getVideoId()));
|
|
|
}
|
|
|
-
|
|
|
- // 异步写Redis
|
|
|
- ThreadPoolFactory.defaultPool().execute(() -> {
|
|
|
- redisTemplate.executePipelined(new SessionCallback<String>() {
|
|
|
- @Override
|
|
|
- public <A, B> String execute(RedisOperations<A, B> redisOperations) throws DataAccessException {
|
|
|
- SetOperations<String, String> operations =
|
|
|
- (SetOperations<String, String>) redisOperations.opsForSet();
|
|
|
- operations.add(key, viewedVideoIds.toArray(new String[viewedVideoIds.size()]));
|
|
|
- redisTemplate.expire(key, videoFilterCacheNewExpire, TimeUnit.SECONDS);
|
|
|
- return null;
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ // 避免穿透
|
|
|
+ viewedVideoIds.add("-1");
|
|
|
}
|
|
|
+ // 异步写Redis
|
|
|
+ ThreadPoolFactory.defaultPool().execute(() -> {
|
|
|
+ redisTemplate.executePipelined(new SessionCallback<String>() {
|
|
|
+ @Override
|
|
|
+ public <A, B> String execute(RedisOperations<A, B> redisOperations) throws DataAccessException {
|
|
|
+ SetOperations<String, String> operations =
|
|
|
+ (SetOperations<String, String>) redisOperations.opsForSet();
|
|
|
+ operations.add(key, viewedVideoIds.toArray(new String[viewedVideoIds.size()]));
|
|
|
+ redisTemplate.expire(key, videoFilterCacheNewExpire, TimeUnit.SECONDS);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(viewedVideoIds)) {
|