ls-use-sql
LS (list) - old version
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
List keys - old (use-sql) version reference page (currently unused)
Usage is ls or ls pattern.
ls lists all keys.
This command is available on Enterprise servers when redis.conf use-sql yes is set.
Example
| Command> | ls With no options, lists all 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 Sorted Set managed per data type, not in the full key set, so it is fast and does not burden the server.
B1 B2 B3 C1 C2 C3 D1 D2 D3
\__C*__/ - When a data type is specified, results are sorted even without the sort option.
- Using "ls user* string" looks up keys starting with user directly.
- If you specify multiple data types, a sorted key list is returned per type.
Example
| Command> | ls * string |
| Result> | 1) "key1" 2) "key2" 3) "key3" |
Specify options
- TYPE: Shows the key data type.
- ENCODING: Shows the internal encoding of the key.
- VALUE or VAL: Shows the value for String keys. This option applies only to String.
- STRLEN: Shows the string length for String keys. This option applies only to String.
- LEN: Shows the length (member count) of the key. Same as running llen for List, scard for Set, zcard for ZSet, hlen for Hash, and xlen for Stream. For String, 1 is shown.
- MEMORY or MEM: Shows memory usage. Same as running memory usage key.
- TTL: Shows expire time in seconds. If expire is not set, -1 is shown.
- PTTL: Shows expire time in milliseconds. If expire is not set, -1 is shown.
- IDLETIME: Shows seconds since the key was last referenced. You can check whether the key was used recently and how long it has been idle.
- SLOT: Shows the key slot. Shown for Cluster and also for Standalone.
- TIME: Shows the key update_mstime (creation time or last modification time).
- EXPIRE_KEYS: Lists keys that have expire time set on members. Combined with TTL, it shows the largest expire time set on members.
- DEFAULT or DF: Applies the type, len, and table options.
Example
| Command> | ls * type |
| Result> |
1) "key" 2) "string" 3) "mylist" 4) "list" 5) "myset" 6) "set" |
| Command> | ls * len |
| Result> |
1) "key" 2) "1" 3) "mylist" 4) "10" 5) "myset" 6) "25" |
| Command> | ls * memory |
| Result> |
1) "key" 2) "54" 3) "mylist" 4) "256" 5) "myset" 6) "614" |
- You can specify a data type and options together.
Example
| Command> | ls * string value |
| Result> |
1) "key1" 2) "value1" 3) "key2" 4) "value2" 5) "key3" 6) "value3" |
| Command> | ls * string strlen |
| Result> |
1) "key1" 2) "6" 3) "key2" 4) "6" 5) "key3" 6) "6" |
Specify sort options
- SORT/ASC/DESC: Sorts the results.
Example
| Command> | ls * sort |
| Result> |
1) "key1" 2) "key2" 3) "key3" |
| Command> | ls * desc |
| Result> |
1) "key3" 2) "key2" 3) "key1" |
Specify COUNT/TOP options
- COUNT integer: Limits the number of keys returned. Can reduce lookup time.
- TOP integer: Limits the number of keys shown after sorting.
Example
| Command> | ls * count 2 |
| Result> |
1) "key2" 2) "key1" |
| Command> | ls * sort top 2 |
| Result> |
1) "key1" 2) "key2" |
Specify the TABLE option
- table: Shows results in table form.
Example
| Command> | ls * string type memory table |
| Result> |
0) "key" "type" "memory" 1) "key1" "string" "52" 2) "key2" "string" "64" |
Syntax
LS [pattern]
[string|list|set|zset|hash|stream]
[type|encoding|value|strlen|len|memory|ttl|pttl|idletime|slot|time|expire_keys|default]
[table]
[sort|asc|desc]
[count <integer>] [top <integer>]
- Available since Enterprise version 6.1.0.
- Time complexity is O(log(N)+M) when a data type is specified.
N is the number of keys of that data type, and M is the number of keys returned.
When not specified: O(N). N is the number of all keys in the database, not the number of returned keys.
| Related commands | SCAN, DBSIZE |
Email
답글이 올라오면 이메일로 알려드리겠습니다.
