Merge pull request #1 from Selly-Modules/get-data-by-pattern

Get data by pattern
This commit is contained in:
Minh Nguyen 2022-03-25 17:10:05 +07:00 committed by GitHub
commit 62529474a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

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