|
@@ -71,15 +71,19 @@ public class RedisActiveKeyIndexRepairService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int removed = 0;
|
|
int removed = 0;
|
|
|
- Set<Object> members = redisCache.redisTemplate.opsForSet().members(target.indexKey);
|
|
|
|
|
- if (members != null) {
|
|
|
|
|
- for (Object member : members) {
|
|
|
|
|
- String cacheKey = member.toString();
|
|
|
|
|
- if (!Boolean.TRUE.equals(redisCache.redisTemplate.hasKey(cacheKey))) {
|
|
|
|
|
- redisCache.redisTemplate.opsForSet().remove(target.indexKey, cacheKey);
|
|
|
|
|
- removed++;
|
|
|
|
|
|
|
+ if (target.isRemoveExpiredFromIndex()) {
|
|
|
|
|
+ Set<Object> members = redisCache.redisTemplate.opsForSet().members(target.indexKey);
|
|
|
|
|
+ if (members != null) {
|
|
|
|
|
+ for (Object member : members) {
|
|
|
|
|
+ String cacheKey = member.toString();
|
|
|
|
|
+ if (!Boolean.TRUE.equals(redisCache.redisTemplate.hasKey(cacheKey))) {
|
|
|
|
|
+ redisCache.redisTemplate.opsForSet().remove(target.indexKey, cacheKey);
|
|
|
|
|
+ removed++;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("索引 {} 跳过过期成员清理,交由 checkFsUserWatchStatus 写库后 untrack", target.name);
|
|
|
}
|
|
}
|
|
|
return new RepairResult(target.name, target.scanPattern, target.indexKey, scannedKeys.size(), added, removed);
|
|
return new RepairResult(target.name, target.scanPattern, target.indexKey, scannedKeys.size(), added, removed);
|
|
|
}
|
|
}
|
|
@@ -104,9 +108,11 @@ public class RedisActiveKeyIndexRepairService {
|
|
|
targets.add(new IndexRepairTarget("liveUserWatchLog",
|
|
targets.add(new IndexRepairTarget("liveUserWatchLog",
|
|
|
"live:user:watch:log:*",
|
|
"live:user:watch:log:*",
|
|
|
LiveKeysConstant.LIVE_USER_WATCH_LOG_INDEX));
|
|
LiveKeysConstant.LIVE_USER_WATCH_LOG_INDEX));
|
|
|
|
|
+ // 心跳索引只补不删:过期 key 由 checkFsUserWatchStatus 写 log_type=4 后再 untrack
|
|
|
targets.add(new IndexRepairTarget("h5wxHeartbeat",
|
|
targets.add(new IndexRepairTarget("h5wxHeartbeat",
|
|
|
CourseWatchKeysConstant.H5_WX_HEARTBEAT_PREFIX + "*",
|
|
CourseWatchKeysConstant.H5_WX_HEARTBEAT_PREFIX + "*",
|
|
|
- CourseWatchKeysConstant.H5_WX_HEARTBEAT_INDEX));
|
|
|
|
|
|
|
+ CourseWatchKeysConstant.H5_WX_HEARTBEAT_INDEX,
|
|
|
|
|
+ false));
|
|
|
targets.add(new IndexRepairTarget("h5wxDuration",
|
|
targets.add(new IndexRepairTarget("h5wxDuration",
|
|
|
CourseWatchKeysConstant.H5_WX_DURATION_PREFIX + "*",
|
|
CourseWatchKeysConstant.H5_WX_DURATION_PREFIX + "*",
|
|
|
CourseWatchKeysConstant.H5_WX_DURATION_INDEX));
|
|
CourseWatchKeysConstant.H5_WX_DURATION_INDEX));
|
|
@@ -144,11 +150,22 @@ public class RedisActiveKeyIndexRepairService {
|
|
|
private final String name;
|
|
private final String name;
|
|
|
private final String scanPattern;
|
|
private final String scanPattern;
|
|
|
private final String indexKey;
|
|
private final String indexKey;
|
|
|
|
|
+ /** false 时仅 SCAN 补登记,不清理索引中已 TTL 过期的成员 */
|
|
|
|
|
+ private final boolean removeExpiredFromIndex;
|
|
|
|
|
|
|
|
public IndexRepairTarget(String name, String scanPattern, String indexKey) {
|
|
public IndexRepairTarget(String name, String scanPattern, String indexKey) {
|
|
|
|
|
+ this(name, scanPattern, indexKey, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public IndexRepairTarget(String name, String scanPattern, String indexKey, boolean removeExpiredFromIndex) {
|
|
|
this.name = name;
|
|
this.name = name;
|
|
|
this.scanPattern = scanPattern;
|
|
this.scanPattern = scanPattern;
|
|
|
this.indexKey = indexKey;
|
|
this.indexKey = indexKey;
|
|
|
|
|
+ this.removeExpiredFromIndex = removeExpiredFromIndex;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean isRemoveExpiredFromIndex() {
|
|
|
|
|
+ return removeExpiredFromIndex;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|