keys
KEYS
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Get keys by key_pattern
The usage is keys key_pattern.
You can use a glob-style pattern.
- * : Matches any characters: h*llo -> hllo, heeeello, etc
- ? : Matches one character: h?llo -> hallo, hello, hxllo, etc
- [alphabet] : Matches a character in the brackets: h[ae]llo -> hallo, hello
- [^e] : Matches any character except those in the brackets:
h[^e]llo -> hallo, hbllo, ... but hello is excluded.
- [a-c] : Matches a character range in the brackets: h[a-c]llo -> hallo, hbllo, hcllo
- \ : To use the special characters above (*?[^]) as literals, prefix them with \.
Example
| Command> | keys * Get all keys |
| Result> |
0) user-1 1) user-2 2) user-30 3) myset 4) meset 5) miset |
| Command> | keys user-* Get keys that start with user- |
| Result> |
0) user-1 1) user-2 2) user-30 |
| Command> | keys *set Get keys that end with set |
| Result> |
0) myset 1) meset 2) miset |
| Command> | keys user-? Get keys that start with user- and have one more character |
| Result> |
0) user-1 1) user-2 |
| Command> | keys m[ye]set Get keys that start with m, then y or e, and end with set |
| Result> |
0) myset 1) meset |
Syntax
KEYS key_pattern
- Available since version 1.0.0.
- Time complexity is O(N). N is the number of all keys in the database, not the number of keys returned.
- This command does a 'full scan' of the DB and can affect server performance, so please avoid using it unless necessary. Be especially careful on production servers with many keys.
| Related commands | SCAN, DBSIZE |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << UNLINK | KEYS | LS >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
