diff options
| author | alex <[email protected]> | 2026-07-07 20:00:53 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-07 20:00:53 +0200 |
| commit | 23eea730585ece03deadd28f46f3c5e46f155048 (patch) | |
| tree | d4d99bb63960da49ba7b636a3262a5632fc09ead /handlers.go | |
| parent | 6c2bdac928beb943a4b0d11d840bf026ec0b7d66 (diff) | |
| download | redis-clone-23eea730585ece03deadd28f46f3c5e46f155048.tar.xz redis-clone-23eea730585ece03deadd28f46f3c5e46f155048.zip | |
added limit argument to KEYS
Diffstat (limited to 'handlers.go')
| -rw-r--r-- | handlers.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/handlers.go b/handlers.go index f298379..13b2d11 100644 --- a/handlers.go +++ b/handlers.go @@ -4,6 +4,7 @@ import ( "errors" "net" "path/filepath" + "sort" "strconv" "time" ) @@ -637,7 +638,6 @@ func handleKeys(conn net.Conn, args []string) { } limit = val } - i := 0 db.mu.Lock() for key := range db.data { matched, err := filepath.Match(pattern, key) @@ -649,11 +649,12 @@ func handleKeys(conn net.Conn, args []string) { if matched { matches = append(matches, key) - i+=1 } - if i == limit{ - break - } + } + + sort.Strings(matches) + if limit != -1 && len(matches) > limit { + matches = matches[:limit] } db.mu.Unlock() |
