diff options
| author | alex <[email protected]> | 2026-07-12 13:48:32 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-12 13:48:32 +0200 |
| commit | 89b3019a3ab77a3e72720342fc0e5bea996fa4f2 (patch) | |
| tree | ed9482c87ff2eaa52ba8359654e0e923a4732e30 /pkg/commands/keys.go | |
| parent | 80100f574d8cf6c231217678356324d8ffa7140f (diff) | |
| download | redis-clone-89b3019a3ab77a3e72720342fc0e5bea996fa4f2.tar.xz redis-clone-89b3019a3ab77a3e72720342fc0e5bea996fa4f2.zip | |
refactored all functions to use the command registry
Diffstat (limited to 'pkg/commands/keys.go')
| -rw-r--r-- | pkg/commands/keys.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pkg/commands/keys.go b/pkg/commands/keys.go new file mode 100644 index 0000000..b233964 --- /dev/null +++ b/pkg/commands/keys.go @@ -0,0 +1,41 @@ +package commands + +import ( + "errors" + "path/filepath" + "redisClone/pkg/core" + "sort" + "strconv" +) + +func Keys(args []string, getShard func(k string) *core.Shard) interface{} { + pattern := args[1] + limit := -1 + if len(args) == 3 { + val, err := strconv.Atoi(args[2]) + if err != nil { + return errors.New("value is not an integer") + } + limit = val + } + + return dbInstance.ExecuteReadAll(func(shards []*core.Shard) interface{} { + var matches []string + for _, shard := range shards { + for key := range shard.Data { + matched, err := filepath.Match(pattern, key) + if err != nil { + return errors.New("illegal glob pattern") + } + if matched { + matches = append(matches, key) + } + } + } + sort.Strings(matches) + if limit != -1 && len(matches) > limit { + matches = matches[:limit] + } + return matches + }) +} |
