From 9f9939418860326b218cf29d61299e582c8ad557 Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Fri, 1 Nov 2024 02:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0key=E7=9A=84=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iClient.go | 7 +++++-- redisKey.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/iClient.go b/iClient.go index 84969cd..f187f6e 100644 --- a/iClient.go +++ b/iClient.go @@ -1,11 +1,12 @@ package redis import ( + "reflect" + "time" + "github.com/farseer-go/collections" "github.com/farseer-go/fs/core" "github.com/go-redis/redis/v8" - "reflect" - "time" ) type IClient interface { @@ -22,6 +23,8 @@ type IClient interface { Del(keys ...string) (bool, error) // Exists key值是否存在 Exists(keys ...string) (bool, error) + // 查找Keys,支持*、?匹配 + Search(searchKeys string) ([]string, error) // StringSet 设置缓存 StringSet(key string, value any) error diff --git a/redisKey.go b/redisKey.go index 51fc039..6218c28 100644 --- a/redisKey.go +++ b/redisKey.go @@ -2,6 +2,7 @@ package redis import ( "context" + "fmt" "strings" "time" @@ -51,3 +52,15 @@ func (receiver *redisKey) Exists(keys ...string) (bool, error) { defer func() { traceDetail.End(err) }() return result > 0, err } + +func (receiver *redisKey) Search(searchKeys string) ([]string, error) { + if searchKeys == "*" { + return nil, fmt.Errorf("考虑性能影响,不支持仅通过*查找") + } + traceDetail := receiver.traceManager.TraceRedis("Search", searchKeys, "") + + result := receiver.GetClient().Keys(context.Background(), searchKeys) + keys, err := result.Result() + defer func() { traceDetail.End(err) }() + return keys, err +}