keys keyword common directives
Here bloggers first set K1 v1 k2 v2
Exists key
Determine if key exists
Move Key Dbnum
Move key values to Dbnum library
Here move K1 to library 2nd, view current library only K2, after switching to library 2nd, view the current K1 has moved over
Expire key seconds
Set the expiration time for a given key
TTL key
See how many seconds are out of date, 1 means never expire, 2 means expired
Then the previous step to the K2 set the 10s expiration time, we have to check his validity period, until the last expiration (-2), notice that it has expired after the deletion, that is, there is no K2 this key.
In general our set key value default validity period is never expires, we reset K1 v1, and then see his expiration date
Type key
View Key Types
Del key
Delete key
String string Common directives
Set key value
Link string value value to key, note that if K1 has been set previously, then we will overwrite the previous value when we set K1 again.
Here we set the value of K1 to V1, then we set the value of K1 again to V11 as follows
Get key
Gets the value of the specified key
Append key value
Add content to the specified key, before our K1 value is v11 append add here, the resulting K1 value is v11add as shown in the figure below.
Strlen Key
Gets the length of the value of the specified key
INCR key
The value of the specified key is increased by +1, only the number can be added and reduced
DECR key
The value of the specified key is reduced by 1, and only the number can be added and reduced.
Incrby Key Step
The value of the specified key is self-increment according to the given step size
Decrby Key Step
The value of the specified key is self-decreasing according to the given step size
GetRange key start subscript end subscript
Gets the value in the specified range, similar to between and from 0 to 1, is to get all, truncate substring
SetRange Key Offset value
Assigns the value of the specified key starting at a certain location, such as K1 's original value V11add, from subscript 2 to the value v22, get v1v22d as follows
Setex Key Validity period value
Setex (set with expire), setting the expiration time for key-value pairs
Setnx Key value
SETNX (set if not exist) sets the value of key to value when and only if key does not exist
Because K1 has been set up before, so use setnx set K1 error, set K4 is OK, because there is no K4
Mset key1 value1 key2 value2 ....
Set multiple key values at once, where M stands for more
Mget key1 key2 Key3 ....
Gets the value of multiple keys at once, where M represents the more
Msetnx
Set multiple key values at once, when and only if key does not exist, note that if the set of multiple keys are already set, some key does not, this operation is all invalid, but not the key is set to succeed
The first time we tried to set K1 K8, because K1 already exists, so the setting failed, the second setting K8 K9 because the current library does not have K8 K9 so the setting succeeds