From 562d8c6f642c4676b617aff33a9fbbea0f8b7f86 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 25 Mar 2022 10:53:25 +0700 Subject: [PATCH 1/4] 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 +} -- 2.34.1 From 1ab40b99b8b984a19bbb2bafd8bf88822831ee20 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 25 Mar 2022 14:35:44 +0700 Subject: [PATCH 2/4] log-test --- get_with_prefix_pattern.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/get_with_prefix_pattern.go b/get_with_prefix_pattern.go index 11b03b6..628ca9c 100644 --- a/get_with_prefix_pattern.go +++ b/get_with_prefix_pattern.go @@ -1,6 +1,9 @@ package redisdb -import "context" +import ( + "context" + "fmt" +) // GetWithPrefixPattern ... func GetWithPrefixPattern(pattern string, limit int64) (keys []string, values []string) { @@ -16,10 +19,12 @@ func GetWithPrefixPattern(pattern string, limit int64) (keys []string, values [] keys, cursor, err = rdb.Scan(ctx, cursor, pattern, limit).Result() if err != nil { + fmt.Println("err redis scan: ", err.Error()) return } if len(keys) == 0 { + fmt.Println("NO keys") return } -- 2.34.1 From 59ae8ffc48127be04b7b981e59e85577e15a8981 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 25 Mar 2022 14:54:28 +0700 Subject: [PATCH 3/4] fix-scan-redis --- get_with_prefix_pattern.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/get_with_prefix_pattern.go b/get_with_prefix_pattern.go index 628ca9c..13c2b98 100644 --- a/get_with_prefix_pattern.go +++ b/get_with_prefix_pattern.go @@ -6,7 +6,7 @@ import ( ) // GetWithPrefixPattern ... -func GetWithPrefixPattern(pattern string, limit int64) (keys []string, values []string) { +func GetWithPrefixPattern(pattern string) (keys []string, values []string) { // Init keys = make([]string, 0) values = make([]string, 0) @@ -17,9 +17,8 @@ func GetWithPrefixPattern(pattern string, limit int64) (keys []string, values [] err error ) - keys, cursor, err = rdb.Scan(ctx, cursor, pattern, limit).Result() + keys, cursor, err = rdb.Scan(ctx, cursor, pattern, 1000000).Result() if err != nil { - fmt.Println("err redis scan: ", err.Error()) return } -- 2.34.1 From b1135a975fd68d6f229520aa39e96c524cbfc0f9 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 25 Mar 2022 16:05:39 +0700 Subject: [PATCH 4/4] remove-logs --- get_with_prefix_pattern.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/get_with_prefix_pattern.go b/get_with_prefix_pattern.go index 13c2b98..a5addab 100644 --- a/get_with_prefix_pattern.go +++ b/get_with_prefix_pattern.go @@ -2,7 +2,6 @@ package redisdb import ( "context" - "fmt" ) // GetWithPrefixPattern ... @@ -23,7 +22,6 @@ func GetWithPrefixPattern(pattern string) (keys []string, values []string) { } if len(keys) == 0 { - fmt.Println("NO keys") return } -- 2.34.1