Redis Common Instruction Operations

Source: Internet
Author: User
Tags set set

Redis is a commonly used database of non relational types.
So we also need to know some of his common operating instructions.

Redis data types are mainly divided into strings, hashes, lists, sets, and so on.

String set--set name 1234//Set key corresponds to a value of string type value Setnx name itcast_new//set key corresponding to a string of values, does not exist then insert success Setex color red Sets the value of the key corresponding to string, and specifies the validity period for this key value SetRange email gmail.com//The function of this command is to cover part of the string corresponding to the key mset Key1 python key2 C + +//Set the value of multiple keys at once, successfully return OK (key1=python,key2=c++) getset name itcast_new//Set key value and return key's old value get--get name//Fetch key corresponding value Range name 0 4//Gets the substring of the value value of the specified key mget key1 key2 Key3//Fetch multiple key values other--INCR age//value of key to do Gaga operation Incrby age 5//Same INC R similar, add the specified value, key does not exist when the key is set, and that the original value is 0 DECR to the value of the key is to reduce operations, decr a nonexistent key, then set the key to 1 Decrby with DECR, minus the specified value append name Redis// Append value to the string value of the specified key hash-dictionary common commands (key--> key value pairs) set--hset myhash field1 "Hello"//Set hash inside field value hsetnx myhash field "he Llo "//Set a nonexistent value, when field exists, set failed Hmset myhash field1" Hello "Field2" World "//set key specified in the hash set the value of the specified field get--hget myhash fie Ld1//Get the specified hash field value Hmget myhash field1 field2//Get all specified hash filed other--hincrby field 1//specified hash Myhash plus Fixed value hexists myhash field1//Tests whether the specified field exists Hlen Myhash//Returns the field quantity of the specified hash Hkeys Myhash//Returns all field Hvals Myhash//return hash of all value hgetall Myhash/ /get all filed and value list--lists in a hash set--lpush mylist "World" insert list from left of queue Rpush mylist "one"//Insert list from right of queue LSET MyList 0
"Four"//sets the value of the list element of index position to get--Lrange mylist 0-1//View the value of all elements in the list lindex mylist 0///The value from the index to find the No. 0 position in the list other-- Lpop mylist//From the queue left an element Llen MyList//Return the length of the list stored in key lrem mylist-2 "Hello"//Remove all elements in the list with Hello set--set set--SA DD myset "Hello"//Add one or more specified member elements to the collection's key get--smembers MySet//Get the number of key other--SCard//collection elements in the collection MySet K
 Ey1 Key2//Get key1 and Key2 difference set Srem myset "one"//delete value in key collection------Delete DEL key keys *//View key values

Reference web site redis Chinese official website http://www.redis.cn/

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.