diff options
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() |
