RebuildBloomFilter 重建布隆过滤器 导出该方法以便外部调用
(ctx context.Context)
| 123 | // RebuildBloomFilter 重建布隆过滤器 |
| 124 | // 导出该方法以便外部调用 |
| 125 | func (cb *CacheBloom) RebuildBloomFilter(ctx context.Context) error { |
| 126 | if cb == nil { |
| 127 | return errors.New("CacheBloom实例不能为空") |
| 128 | } |
| 129 | |
| 130 | newBF := bloom.NewWithEstimates(1000000, 0.01) |
| 131 | |
| 132 | // 使用SCAN命令替代KEYS,避免阻塞Redis |
| 133 | iter := cb.client.Scan(ctx, 0, "*", 0).Iterator() |
| 134 | for iter.Next(ctx) { |
| 135 | newBF.AddString(iter.Val()) |
| 136 | } |
| 137 | if err := iter.Err(); err != nil { |
| 138 | return err |
| 139 | } |
| 140 | |
| 141 | cb.bf = newBF |
| 142 | return nil |
| 143 | } |
| 144 | |
| 145 | // isNil 使用反射检查值是否为 nil |
| 146 | func isNil(value interface{}) bool { |
nothing calls this directly
no outgoing calls
no test coverage detected