diff --git a/src/taoensso/carmine.clj b/src/taoensso/carmine.clj index fe6b3fe9..b3e72334 100644 --- a/src/taoensso/carmine.clj +++ b/src/taoensso/carmine.clj @@ -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 \"*\") => Set of all keys + (scan-keys \"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