MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / RebuildBloomFilter

Method RebuildBloomFilter

pkg/cachep/bloom/cachebloom.go:125–143  ·  view source on GitHub ↗

RebuildBloomFilter 重建布隆过滤器 导出该方法以便外部调用

(ctx context.Context)

Source from the content-addressed store, hash-verified

123// RebuildBloomFilter 重建布隆过滤器
124// 导出该方法以便外部调用
125func (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
146func isNil(value interface{}) bool {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected