ls
LS (list)
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
List keys
Usage is ls or ls key_pattern.
ls lists keys.
Example
| Command> | ls With no options, lists keys |
| Result> |
0) user-1 1) user-2 2) user-30 3) myset 4) meset 5) miset |
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 inside 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 in the range: h[a-c]llo -> hallo, hbllo, hcllo
- \ : Prefix special characters (*?[^]) with \ to use them literally.
Example
| Command> | ls * List all keys |
| Result> |
0) user-1 1) user-2 2) user-30 3) myset 4) meset 5) miset |
| Command> | ls user-* List keys starting with user- |
| Result> |
0) user-1 1) user-2 2) user-30 |
| Command> | ls *set List keys ending with set |
| Result> |
0) myset 1) meset 2) miset |
| Command> | ls user-? List keys starting with user- plus one character |
| Result> |
0) user-1 1) user-2 |
| Command> | ls m[ye]set List keys starting with m, then y or e, ending with set |
| Result> |
0) myset 1) meset |
Specify a data type
You can specify a data type to list only those keys. Allowed data types are string, list, set, zset, hash, stream.
- When a data type is specified, keys are looked up in the Hash Table (Dictionary) managed per data type, not in the full key set.
Example
| Command> | ls * string |
| Result> | 1) "key1" 2) "key2" 3) "key3" |
Syntax
LS [key_pattern] [string|list|set|zset|hash|stream] [COUNT count]
- Available since Ent 8.1.0.
- Time complexity is O(N).
| Related commands | SCAN, DBSIZE |
| << KEYS | LS | LL >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
