| 76 | } |
| 77 | |
| 78 | func (c *checkCache) DeleteKeysWithPattern(ctx context.Context, pattern string) error { |
| 79 | var cursor uint64 |
| 80 | |
| 81 | for { |
| 82 | // 执行 SCAN 命令 |
| 83 | keys, cursor, err := c.client.Scan(ctx, cursor, pattern, 100).Result() |
| 84 | if err != nil { |
| 85 | return fmt.Errorf("failed to scan Redis keys: %w", err) |
| 86 | } |
| 87 | |
| 88 | // 如果找到匹配的键,进行删除 |
| 89 | if len(keys) > 0 { |
| 90 | if err := c.client.Del(ctx, keys...).Err(); err != nil { |
| 91 | return fmt.Errorf("failed to delete Redis keys: %w", err) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // 如果 cursor 为 0,说明遍历结束 |
| 96 | if cursor == 0 { |
| 97 | break |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | // GetCacheList 从缓存中获取审核记录列表 |
| 105 | func (c *checkCache) GetCacheList(ctx context.Context, key string) ([]domain.Check, error) { |