Skip to content

Commit

Permalink
[new] Add scan-keys util
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Dec 21, 2022
1 parent 311c913 commit 80067bc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/taoensso/carmine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,23 @@
{}
(fn [cursor] (wcar {} (hscan "test:foo" cursor))))))

(defn scan-keys
"Returns a set of Redis keys that match the given pattern.
Like the Redis `keys` command, but implemented using `scan` so safe to
use in production.
(scan-keys <conn-opts> \"*\") => Set of all keys
(scan-keys <conn-opts> \"foo:*\") => Set of all keys starting with \"foo:\""

[conn-opts pattern]
(persistent!
(reduce-scan enc/into!
(transient #{})
(fn [cursor]
(wcar conn-opts (scan cursor "MATCH" pattern))))))

(comment (scan-keys {} "*"))

;;;; Deprecated

(enc/deprecated
Expand Down

0 comments on commit 80067bc

Please sign in to comment.