redisdb/get_with_prefix_pattern.go

36 lines
556 B
Go
Raw Permalink Normal View History

2022-03-25 03:53:25 +00:00
package redisdb
2022-03-25 07:35:44 +00:00
import (
"context"
)
2022-03-25 03:53:25 +00:00
// GetWithPrefixPattern ...
func (s Server) GetWithPrefixPattern(pattern string) (keys []string, values []string) {
2022-03-25 03:53:25 +00:00
// Init
keys = make([]string, 0)
values = make([]string, 0)
var (
ctx = context.Background()
cursor uint64
err error
)
keys, cursor, err = s.rdb.Scan(ctx, cursor, pattern, 1000000).Result()
2022-03-25 03:53:25 +00:00
if err != nil {
return
}
if len(keys) == 0 {
return
}
// Get value
for _, key := range keys {
value := s.GetValueByKey(ctx, key)
2022-03-25 03:53:25 +00:00
values = append(values, value)
}
return
}