optimize get all keys logic in RedisCacheIndex feature

pull/385/head
Michael Li 1 year ago
parent ed909ba497
commit 65dc7d0738
No known key found for this signature in database

@ -59,9 +59,22 @@ func (s *redisCacheTweetsCache) delTweets(keys []string) error {
return s.c.Do(context.Background(), cmd).Error()
}
func (s *redisCacheTweetsCache) allKeys() ([]string, error) {
cmd := s.c.B().Keys().Pattern(_cacheIndexKeyPattern).Build()
return s.c.Do(context.Background(), cmd).AsStrSlice()
func (s *redisCacheTweetsCache) allKeys() (res []string, err error) {
cursor := uint64(0)
for {
cmd := s.c.B().Scan().Cursor(cursor).Match(_cacheIndexKeyPattern).Count(50).Build()
entry, err := s.c.Do(context.Background(), cmd).AsScanEntry()
if err != nil {
return nil, err
}
res = append(res, entry.Elements...)
if entry.Cursor != 0 {
cursor = entry.Cursor
continue
}
break
}
return
}
func (s *redisCacheTweetsCache) Name() string {

Loading…
Cancel
Save