Skip to content

Commit

Permalink
添加key的模糊查找
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Oct 31, 2024
1 parent e9c9aaf commit 9f99394
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions iClient.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions redisKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"context"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -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
}

0 comments on commit 9f99394

Please sign in to comment.