I. Type Overview
Redis string type is the most basic type of data storage, it is binary safe in Redis, this would mean that the type can accept data in any format, such as JPEG image data or Json object description information. Data type Value length of the string can accommodate up in Redis is 512M.
Second, the relevant command
1, class assignment
Example: set key val
Usage: used to set the value of a given key. If the key is already stored other value, SET will overwrite the old value, and ignore type .
Returns: OK successful return
127.0.0.1:6379> set name jack
OK
Example: mset key ... keyn val1 ... valn
Usage: commands for simultaneously providing one or more key-value pair.
Returns: Always return OK
127.0.0.1:6379> mset key1 key2 key3 val1 val2 val3
OK
Example: setnx key val
Usage: Redis Setnx (SET if Not eXists ) command specified key does not exist , setting the specified value key.
Return: key does not exist to set a successful return to 1, key exist return 0
127.0.0.1:6379> setnx name jack
(integer) 0
Example: append key val
Usage: if the key is a string already exists, APPEND command value appended to the end of the original value key.
If the key does not exist, APPEND is simply set to a given key value, the same as the implementation SET key value.
Returns: After adding a specified value, the key string length.
127.0.0.1:6379> append name boy
(integer) 7
127.0.0.1:6379> append job doctors
(integer) 7
2, the value of class
Example: get key
Usage: used to obtain the value of the specified key. If the key does not exist, returns nil. If the key value is not stored in the string type, an error is returned.
Returns: the value of the key, if the key does not exist, returns nil. If the key is not a string type, an error is returned.
127.0.0.1:6379> get name
"jack"
Example: mget key1 .... keyn
Usage: Returns all (one or more) of values of the given key. If a given key inside, there are some key does not exist, this key returns the special value nil.
Returns: a list of all the given key value included.
127.0.0.1:6379> mget key1 key2 key3
1) "key2"
2) (nil)
3) "val1"
Example: strlrn key
Usage: used to obtain the value of the length of the string stored in the specified key. When the key is not stored string values, an error is returned.
Returns: the length of the string value. When the key is not present , it returns 0.
127.0.0.1:6379> strlen name
(integer) 4
3, operation type
Example: incr key (default operation 1)
Usage: If the key is not present, then the value of the key will first be initialized to 0, and then perform operations INCR.
If the value type or string type containing the error can not be represented as a number, an error is returned.
Returns: the value of the key after executing INCR command.
Example: incrby key num
Usage: If the key is not present, then the value of the key will first be initialized to 0, and then perform operations INCR.
If the value type or string type containing the error can not be represented as a number, an error is returned.
Returns: the value of the key after executing INCR command.
Example: decr key (default operation 1)
Usage: If the key is not present, then the value of the key will first be initialized to 0, and then perform operations DECR.
If the value type or string type containing the error can not be represented as a number, an error is returned.
Returns: the value of the key after executing DECR command.
Example: decrby key val
Usage: If the key is not present, then the value of the key will first be initialized to 0, and then perform operations DECR.
If the value type or string type containing the error can not be represented as a number, an error is returned.
Returns: the value of the key after executing DECR command.
127.0.0.1:6379> set math 20
OK
127.0.0.1:6379> incr math
(integer) 21
127.0.0.1:6379> incrby math 20
(integer) 41
127.0.0.1:6379> decr math
(integer) 40
127.0.0.1:6379> decrby math 20
(integer) 20
127.0.0.1:6379>