2022-03-25 03:53:25 +00:00
|
|
|
package redisdb
|
|
|
|
|
2022-03-25 07:35:44 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
2022-03-25 03:53:25 +00:00
|
|
|
|
|
|
|
// GetWithPrefixPattern ...
|
|
|
|
func GetWithPrefixPattern(pattern string, limit int64) (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, limit).Result()
|
|
|
|
if err != nil {
|
2022-03-25 07:35:44 +00:00
|
|
|
fmt.Println("err redis scan: ", err.Error())
|
2022-03-25 03:53:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(keys) == 0 {
|
2022-03-25 07:35:44 +00:00
|
|
|
fmt.Println("NO keys")
|
2022-03-25 03:53:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get value
|
|
|
|
for _, key := range keys {
|
|
|
|
value := GetValueByKey(ctx, key)
|
|
|
|
values = append(values, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|