One, String
Overview: String is the most basic type of Redis, the largest storage of 512MB of data, String type is binary security, that is, you can store any data, such as numbers, pictures, serialized objects, etc.
1, set up
A, set the key value
Set key value
b, set key value and expiration time, in seconds
Setex Key seconds value
C, set multiple key values
Mset key value [key value ...]
2. Get
A, gets the value according to the key, if the key does not exist then returns none (Null 0 nil)
Get key
b, get multiple values based on multiple keys
Mget key [Key ...]
3, Operation
Requirement: value is a string-type number
A, the value of the key plus 1
INCR key
b, the value of the key corresponding to minus 1
DECR key
C, add a key to the value of the integer
Incrby Key Intnum
D, add the value of the key to the integer
Decrby Key Intnum
4. Other
A, append value
Append key value
b, get the value length
Strlen Key
Second, key
1, lookup key, parameter support regular
Keys pattern
2, to determine whether the key exists, if there is a return of 1, does not exist to return 0
Exists key
3, view the key corresponding value type
Type key
4, delete the key and corresponding value
Del key [Key ...]
5, set the expiration time, in seconds
Expire key seconds
6, view the effective time, in seconds
TTL key
Three, hash
Overview: Hash is used to store objects
{
Naem: "Tom",
Age:18
}
1. Set
A, set a single value
hset key field value
B, set multiple values
hmset key field value [Field value ...]
2. Get
A, get the value of a property
hget key field
B, get the value of multiple properties
hmget key filed [filed ...]
C, get all the properties and values
hgetall key
D, get all
the properties Hkeys key
E, get all
the values Hvals key
F, and return the number of included data
Hlen Key
3, other
A, to determine whether the property exists, exists to return 1, does not exist to return 0
hexists key field
B, delete attributes and values
hdel key field [field ...]
C, string length of the return value
hstrlen key field
Four, List
Overview: The element type of the list is string, sorted in the order of insertion, adding elements to the head or tail of the list
1. Set
A, insert
lpush key value [Vlaue ...]
in the head. B, insert
rpush key value [Vlaue ...]
at the tail end. C, before the first | of an element, insert a new element
Linsert key Before|after pivot value
D, set the element value for the specified index
lset key index value
Note: Index starts at 0
Note: The index value can be a negative number, indicating that the offset starts at the end of the list, such as-1 for the last element
2, get
A, remove and return the first element of the list of key
Lpop key
B, Removes and returns the last element of the list for key
Rpop key
C, returns the specified range of elements stored in the key's list
Lrange key start end note: Start end
is starting from 0
Note: The offset can be negative
3, other
A, cropped list, a subset of the original set
LTrim key start end
Note: Start end is starting
from 0 Note: The offset can be negative
B, return the length of the list stored in key
Llen key
C, return the value of the index in the list
lindex key index
Five, set
Overview: Unordered collection, element type string, element uniqueness, no repetition
1. Set
A, add element
sadd key member [...]
2, Get
A, return the key set all elements
smembers key
B, return the number
of elements SCard key
3,
A, to find the intersection of multiple sets
sinter key [key ...]
b, to find multiple sets of the difference set
sdiff key [key ...]
C, to find the collection of multiple sets
sunion key [key ...]
D, to determine if the element is in the collection, there is a return of 1, there is no return 0
sismember Key member
VI. Zset
Overview: A, ordered set, element type is sting, element is unique, cannot repeat
b, each element is associated with a double type of score (weight), sorted by the size of the weights, the score of the elements can be the same
1, set
A, add
zadd key score member [score ...]
Zadd Z1 1 a 5 B 3 C 2 d 4 E
2, get
A, return the specified range of elements
zrange key start end
B, return element number
Zcard key
C, return ordered set In the key, score the number of elements between Min and Max
zcount key min Max
D, return the ordered set key, member's score value
zscore key