From 562d8c6f642c4676b617aff33a9fbbea0f8b7f86 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 25 Mar 2022 10:53:25 +0700 Subject: [PATCH] get-data-by-pattern --- get_with_prefix_pattern.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 get_with_prefix_pattern.go diff --git a/get_with_prefix_pattern.go b/get_with_prefix_pattern.go new file mode 100644 index 0000000..11b03b6 --- /dev/null +++ b/get_with_prefix_pattern.go @@ -0,0 +1,33 @@ +package redisdb + +import "context" + +// 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 { + return + } + + if len(keys) == 0 { + return + } + + // Get value + for _, key := range keys { + value := GetValueByKey(ctx, key) + values = append(values, value) + } + + return +}