|
|
@@ -202,6 +202,10 @@ public class KuaishouHotStore {
|
|
|
public void ensureGroup(String group) {
|
|
|
if (group == null || group.isBlank()) return;
|
|
|
if (initializedGroups.contains(group)) return;
|
|
|
+ if (groupExists(group)) {
|
|
|
+ initializedGroups.add(group);
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
redis.opsForStream().createGroup(stream, ReadOffset.from("0"), group);
|
|
|
initializedGroups.add(group);
|
|
|
@@ -214,6 +218,10 @@ public class KuaishouHotStore {
|
|
|
var id = redis.opsForStream().add(org.springframework.data.redis.connection.stream.StreamRecords
|
|
|
.newRecord().ofMap(Collections.singletonMap("_init", "1")).withStreamKey(stream));
|
|
|
if (id != null) redis.opsForStream().delete(stream, id);
|
|
|
+ if (groupExists(group)) {
|
|
|
+ initializedGroups.add(group);
|
|
|
+ return;
|
|
|
+ }
|
|
|
redis.opsForStream().createGroup(stream, ReadOffset.from("0"), group);
|
|
|
initializedGroups.add(group);
|
|
|
} catch (Exception retryEx) {
|
|
|
@@ -339,6 +347,15 @@ public class KuaishouHotStore {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private boolean groupExists(String group) {
|
|
|
+ try {
|
|
|
+ var groups = redis.opsForStream().groups(stream);
|
|
|
+ return groups != null && groups.stream().anyMatch(info -> group.equals(info.groupName()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private boolean isBusyGroupError(Throwable e) {
|
|
|
while (e != null) {
|
|
|
if (e.getMessage() != null && e.getMessage().contains("BUSYGROUP")) return true;
|