NoSQL Technology--redis Series--redis data types and corresponding command--string types

Source: Internet
Author: User



1:redis's official website address is: http://www.redis.com



Online Redis command Run test address: http://try.redis.io/



There are 5 types of data for 2:redis: String, Hash, Set, List, SortedSet






String type



1) string is binary secure



(1): Set indicates setting key and value



eg:> set name Lusy



Ok



>get Name



Lusy



Note: The same name corresponds to the same value in Redis



(2) Setnx: Set key corresponding to the value of string type value, if key exists return 0, do not reset the new value, if it does not exist, set the key and value key value pairs.



Eg:>setnx name haha



(integer) 0



>get Name



Lusy



>setnx name1 yy



Ok



>get name1



Yy



(3) Setex sets the value of the key corresponding to string type value and sets the validity period for this key value.



>setex Name2 Ten JJ



Ok



>get name2



Jj



>get name2



Jj



>get name2



Jj



>get name2



(nil) indicates an empty






No expiration date Love table is permanent, Redis command is case-insensitive



(4): SetRange Sets the substring form of the value of the specified key: SetRange key StartIndex SubStr



StartIndex represents the place to begin the substitution, the first is the new string to be replaced with, and only the string of substr length is replaced, and the remaining strings remain unchanged. The length of the pay is returned when the statement is executed successfully,



eg


> Get name"Redistry"> SetRange 6 SubStr(Error) Wrong number of arguments (2 for 3)> SetRange 6 Str(Error) Wrong number of arguments (2 for 3)> SetRange name 6 subStr A> Get name"Redistsubstr"


(5): Mset Set the value of multiple keys at once, the successful return OK means that all keys and values are set, the failure returns 0, indicating that no key and value are set successfully



eg


> Mset name haha name2 JJ Name3 JuJuOK> Get name"haha"> Get name2"JJ"> Get Name3"JuJu"


(6): Msetnx key1 value1 ky2 value2



Setting multiple key value can only be set if key is not present, and only one key value is not set successfully. return 0 indicates failure



eg


> Msetnx name Hefei name3 Changchun name4 Jilin(integer) 0> Get name"haha"> Get Name3"JuJu"> Get name4(nil)> Mset name5 beijin name6 ShanghaiOK> Get name5"Beijin"> Get Name6"Shanghai"


(7): Getset key NewValue



Represents a new value that sets key and returns the original value



Eg:


> Set Place guangzhouOK> Get Place"Guangzhou"> Getset Place Hangzhou"Guangzhou"> Get Place"Hangzhou"


(8): Append key value appends a value to a key to successfully return the length of the new value



eg


> Append Place hah One> Get Place"Hangzhouhah"


(9): Mget key1 key2 Key3 Obtain the corresponding value of these keys, nil if no value is present



eg


> Mget name1 name2 name3 name4 name5 name6 name61) (nil)
2) "JJ"
3) "JuJu"
4) (nil)
5) "Beijin"
6) "Shanghai"
7) "Shanghai"


(Ten): Bitcount key [start] [end] Statistic string Specifies the number of bytes from the starting position



Calculates the number of bits that are set to the given string1.



In general, a given entire string is counted, and by specifying additional or parameters, the count can be made only on astartendparticular bit.



startandendthe parameter settings are similar to the GETRANGE command, you can use negative values: for example, to-1represent the last byte, to-2represent the second-lowest byte, and so on.



Non-existent is treated as ankeyempty string, so an operation that does not existkeyBITCOUNTresults in0



eg


> Set name 123OK> Get name"123"> Bitcount nameTen> Bitcount nameTen> Bitcount Count0> Set Test 1OK> Get Test"1"> Bitcount Test3> Set name 0OK> Get Naem(nil)> Get name"0"> Bitcount name2> Set name 3OK> Get name"3"> Bitcount name4


(one): GetRange key Start end



Gets the specified substring of the valu corresponding to the key


eg:> Set name JilindaxueOK> GetRange Name 1 4"Ilin"


(+1): incr key increment that is the execution of the atom when key does not exist, will create one, and initialize to 0 and then perform the atomic +1 operation.


> Set Key1 2OK> INCR key1(integer) 3> Get Key5(nil)> INCR key5(integer) 1


(+): Incrby key Step adds key step if key does not exist it will generate a key and initialize me 0 when step>0 represents an increase, step<0 means less



eg


> INCR key1(integer) 3> Incrby key1 5(integer) 8> Get Key2(nil)> Incrby key2 7(integer) 7


:d EC is same as Incr,decrby are same as Incrby



eg


> DECR key 6(Error) Wrong number of arguments (2 for 1)> DECR key6(integer)-1> Decrby key7(Error) Wrong number of arguments (1 for 2)> Decrby key7 9(integer)-9


(): Strlen key



Look at the length of the string if key does not exist return 0


> Strlen key11(integer) 0> Get name"Jilindaxue"> strlen name(integer) Ten








NoSQL Technology--redis Series--redis data types and corresponding command--string types


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.