Data types for Redis
(1) Strings type and operation
String is the simplest type, a key corresponding to a value,string type is binary safe, Redis string can contain any data, such as JPG images or serialized objects
1.Set
sets the value of the key corresponding to string type
For example: We add a Name=hello key-value pair
command: Set name Hello
2.Get
gets the value that the key corresponds to
command: Get name
3.Setnx
sets the value of the key corresponding to the string type of value, if key
already exists, returning 0,nx is not exist meaning
command: setnx name Hello
Expand Getnx
4.Setex
sets the value of the key corresponding to string type value and specifies this keyvalid value corresponding to
command: Setex haircolor Red
10 is 10 seconds
5.Setrange
sets the string for the value of the specified key
For example: We want Lijie 126 mailboxes to be replaced with Gmail mailboxes
set name [email protected]
command: SetRange name 6 gmail.com
6.mset
setting the value of multiple keys at once, successfully returning OK means that all values areset, the failure returns 0 to indicate that no value is set
7.msetnx
setting multiple key values at once, successfully returning OK means that all values are setfailure to return 0 means that no value is set, but does not overwrite the existing key
8.getset
sets the value of key and returns the old value of key
9.getrange
gets the substring of the value of the key
10mget
gets the value of more than one key at a time, if the corresponding key does not exist, the corresponding return nil
11.INCR
adds an operation to the value of key and returns a new value
12.incrby
similar to INCR, plus the specified value, key does not exist when the key is setand thinks the original value is 0.
13.append
appends value to the string of the specified key, returning the length of the new string value
--------------------------------------------------------Gorgeous split-line--------------------------------------------------
(2) Hashes type and Operation
Redis Hash is a string type of field and value mapping table, its addition, delete operations are O (1) (average) hash is particularly suitable for storing objects, compared to the object of each word Gencun into a single string type, Storing an object in a hash type consumes less memory and makes it easier to access the entire object
1.hset
sets the hash field to the specified value, and if key does not exist, first create
hset user:001 name Miao
2.hsetnx
sets the hash field to the specified value, and if key does not exist, it is created first,
If there is a return of 0
3.hmset
command: Hmset user:002 name miao sex 1
4.hget
command: Hget user:002 name
5.hincrby
command: Hincrby user:name age 6
6.hexists
test to specify whether the field exists
7.hlen
returns the number of field in a hash
8.hdel
Delete field in hash
Hdel user:002 Age
9.hkeys
command: Hkeys user:002
10.hvals
command: Hvals user:002
11.hgetall
command: Get all field and value of a hash
Redis Learning (2)-data type string and hashes