Several basic commands for Redis

Source: Internet
Author: User
Tags delete key

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.