Redis Learning Notes (additions and deletions)

Source: Internet
Author: User

Redis Learning Notes (add and subtract) adds a key to the database

SET key value

Get the key in the database

KEYS pattern

Pattern supports GLOB style wildcard format

"?" matches one character

"*" matches any character

"[]" matches any one of the characters between parentheses, you can use the "-" symbol to represent a range, for example: A[a-z]c

"\x" matches the character X, which is used to escape characters. If you need to match "?", you need to use \?

Keys * (deprecated, queries can affect performance if too many keys are in the library)

Determine if a key exists

How to exist returns 1, does not exist return 0:

redis> Exists key

(integer) 1

Delete key

Redis> del key ... .

Multiple keys can be deleted at the same time, the number of deleted keys will be returned, and if no this key will return 0

High-performance removal

The DEL command does not support wildcards and can be combined with the Linux pipeline and the Xargs command to remove all rules-compliant keys

For example: Delete all keys that begin with "haha:".

Under the Linux command line:

redis-cli KEYS "haha:*" | xargs redis-cli DEl   (单个key作为参数)redis-cli del ‘redis-cli keys "haha:*"‘    (多个键作为参数..没测成功)
Gets the data type of the key value
TYPE *key*

The return value may be string (string type), hash (hash type), list (list type), set (collection type), Zset (ordered collection type)

Redis Learning Notes (additions and deletions)

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.