Redis Learning Note (ii)-key related commands

Source: Internet
Author: User

  The various data types supported by Redis include String,list, set, sorted set, and hash.

REdis is essentially a key-value db, so let's start by looking at his key. First, the key is also a string type, but the key cannot include boundary characters. because key is not a binary safe string, such as "My Key" and "mykey\n" keys that contain spaces and line breaks are not allowed. by the way, the use of binary characters is not restricted within Redis, which is limited by the Redis protocol. "\ r \ n" is used as a special character in the protocol format.

Some of the commands in the Redis 1.2 protocol have begun to use the new protocol format (such as Mset). In short, the inclusion of boundary characters as illegal key bar, so as to avoid being entangled by the bug. In addition to the introduction of a format convention for key, Object-type:id:field. For example, User:1000:password,blog:xxidxx:title, and the length of the key should not be too long. The reason is obviously the memory ah, and the lookup time relatively short key is also slower. However, it is not recommended to have short keys, such as U:1000:PWD. Obviously, the above user:1000:password is very readable.

  Get and the Set command:

  

  Key-related commands:

  exits key test Specifies whether key exists, returns 1 for presence, 0 does not exist

  

  del key1 key2 .... KeyN deletes the given key, returns the number of deleted keys, 0 means the given key does not exist

  

  Type key returns the value type of the given key. The return none indicates that there is no key,string character type, the list linked list type set unordered collection type ...

  

  keys pattern returns all keys that match the specified pattern

  

  Randomkey Returns a randomly selected key from the current database and returns an empty string if the current database is empty

  

  Rename Oldkey Newkey the Atom is renamed a key, and if the newkey exists, it will be overwritten. If Oldkey does not exist or is the same as Newkey, an error message is returned.

      

  Renamenx oldkey Newkey Ibid, but if Newkey exists return failure

  dbsize Returns the number of keys for the current database

  

  expire key seconds Specifies the expiration time, in seconds, for the key. Returns 1 success, 0 indicates that key has been set to expire or does not exist

  TTL key returns the remaining expiration seconds of a key that has set an expiration time-1 indicates that key does not exist or has not been set to expire

  

  Select db-index selects the database by index, the default connection database is all 0, and the default number of databases is 16. Returns 1 indicates success, 0 failed

  

  Move key Db-index moves the key from the current database to the specified database. Returns 1 success. 0 if key does not exist or is already in the specified database

  

  FLUSHDB Delete all keys in the current database, this method does not fail. Use with caution

  Flushall All keys in all databases are deleted, this method does not fail. More cautious use

  

Redis Learning Note (ii)-key related commands

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.