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() return s.c.Do(context.Background(), cmd).Error()
} }
func (s *redisCacheTweetsCache) allKeys() ([]string, error) { func (s *redisCacheTweetsCache) allKeys() (res []string, err error) {
cmd := s.c.B().Keys().Pattern(_cacheIndexKeyPattern).Build() cursor := uint64(0)
return s.c.Do(context.Background(), cmd).AsStrSlice() 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 { func (s *redisCacheTweetsCache) Name() string {

Loading…
Cancel
Save