KEYS

Synopsis

KEYS patternReturns all keys matching pattern. An error is thrown if over 10,000 keys are in the db to protectagainst an out of memory state, although this limit can be changed.

Supported patterns:

  • ?oo matches foo, boo, zoo, …
  • *oo matches oo, foo, fllllloo, …
  • [fb]oo matches foo and boo.
  • [^f]oo matches boo, zoo, … but not foo.
  • [f-g]oo matches foo and goo.

Use \ to escape special characters if you want to match them verbatim.

Return Value

String array with the list of matching keys, error if there are over 10,000 keys. There is noordering invariant on the returned keys.

Examples

  1. $ ZADD z_key 1.0 v1
  1. (integer) 1
  1. $ SADD key val
  1. (integer) 1

Get all keys in the db.

  1. $ KEYS *
  1. 1) "key"
  2. 2) "z_key"

Get keys matching a specific pattern.

  1. $ KEYS ?ey
  1. 1) "key"