1.KEYS pattern: Get the list of key names that match the rules pattern supports GLOB style wildcard format, such as:
Symbol |
Meaning |
? |
Match one character |
* |
Match any of the characters (including 0) |
[] |
Match any of the characters between parentheses, you can use the "-" symbol to denote a range, such as a[b-d] can match "AB", "AC", "AD" |
\x |
Matches the character X, which is used to escape symbols. If you want to match "?" You need to use \? |
such as:redis>
KEYS *
Note: The keys command needs to traverse all the keys in Redis, which can affect performance when the number of keys is high, and is not recommended for use in a production environment .
tip: Redis does not differentiate between command case.
2.EXISTS key:
determine if a key existsReturns an integer type of 1 if the key exists, otherwise returns 0. Such as:
redis> EXISTS bar
3.DEL key [key ...] : Delete key You can delete one or more keys, and the return value is the number of deleted keys. such as:
reids> DEL bar
tip:The parameters of the DEL command do not support wildcards , but we can combine the Linux pipeline and the Xargs command to remove all the rules that match the key. For example, to delete all the keys that start with "User:", you can execute redis-cli keys "user:*" | xargs redis-cli DEL. In addition, because the DEL command supports multiple keys as parameters, it is also possible to execute redis-cli DEL ' redis-cli keys "user:*" to achieve the same effect, but with better performance.
4.TYPE key : Gets the data type of the value gets the data type of the key value, which may be a string (type), hash (hash type), list (list type), set (collection type), Zset (ordered collection type). such as:redis> SET Foo 1OKredis>
TYPE foo stringredis> Lpush Bar 1(integer)redis>
TYPE bar List the function of the Lpush command here is to add an element to the specified list type key and create it if the key does not exist.
Several basic commands for Redis