Xinxing analyzes key-related commands in Redis, and Xinxing analyzes rediskey

Source: Internet
Author: User
Tags redis server

Xinxing analyzes key-related commands in Redis, and Xinxing analyzes rediskey

In Redis, we can also directly operate on keys. The following are common commands:

(1) keypattern: It indicates getting all the keys matching pattern. Note that we should avoid using this command because it is very time-consuming for large databases, the performance of the Redis server is also a big blow. It supports the wildcard format of glob-style. For example, if "*" is used to represent any one or more characters, "?" is used? [Xyz] represents any letter in square brackets.

(2) del key... it is used to delete the specified keys from the database. If the specified key does not exist, ignore it directly. In addition, we also need to point out that if the data type associated with the key is not string, but list, set, hash, sorted-set, and so on, the time complexity of deleting each key is o (M). M indicates the number of elements in the container. For keys of the string type, the time complexity is o (1 ).

(3) exists key to determine whether the specified key exists. If 1 is returned, 0 is returned, and no is returned.

(4) move key db moves the key specified in the current database to the database specified in the parameter. If the key already exists in the target database or does not exist in the current database, this command does not perform any operations and returns 0. If the movement is successful, 1 is returned. Otherwise, 0 is returned.

(5) rename key newkey is used to rename the specified key. If the two keys in the parameter have the same command or the original key does not exist, this command will return related error information. If newkey already exists, it will be overwritten directly.

(6) renamenx key newkey if the new value does not exist, the original value in the parameter is changed to a new value. If the new value exists, it is not overwritten.

(7) If the persist key has an expiration time, the command will remove the expiration time so that the key can be stored persistently instead of timeout.

(8) expire key seconds this command sets the time-out seconds for the key specified in the parameter. After this time is exceeded, the key is automatically deleted. If the key is modified before the time-out, the timeout associated with the key will be removed.

(9) Time-out seconds for the ttl key to obtain the key.

(10) randomkey returns a random key from the currently opened database.

(11) The type key is used to obtain the value type associated with the specified key in the parameter. This command will be returned in string format.

(12) The sort key command is a bit complicated. It can be followed by many other modifiers. It returns the sorted original list.




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.