fix: cross devices skip configs sync

This commit is contained in:
shinya
2025-07-29 21:30:20 +08:00
parent 10f2dc1904
commit b5e351bb9c
9 changed files with 165 additions and 5 deletions

View File

@@ -332,6 +332,36 @@ export class RedisStorage implements IStorage {
this.client.del(this.skipConfigKey(userName, source, id))
);
}
async getAllSkipConfigs(
userName: string
): Promise<{ [key: string]: SkipConfig }> {
const pattern = `u:${userName}:skip:*`;
const keys = await withRetry(() => this.client.keys(pattern));
if (keys.length === 0) {
return {};
}
const configs: { [key: string]: SkipConfig } = {};
// 批量获取所有配置
const values = await withRetry(() => this.client.mGet(keys));
keys.forEach((key, index) => {
const value = values[index];
if (value) {
// 从key中提取source+id
const match = key.match(/^u:.+?:skip:(.+)$/);
if (match) {
const sourceAndId = match[1];
configs[sourceAndId] = JSON.parse(value as string) as SkipConfig;
}
}
});
return configs;
}
}
// 单例 Redis 客户端