# 1. Set a value-key SET key value # 2. Get the value of key GET key # then set (NX) 3. When the key is not present SET key value NX # 4. Set expiration time (EX) through the date on automatically destroyed ex px milliseconds seconds sET value ex seconds The Key # 5. The plurality of simultaneously-value Key MSET VALUE1 key1 key2 value2 value3 key3 # 6. The multiple simultaneously acquired value-Key mget key1 key2 key3
# 1. Obtain length strlen Key # 2. Get the specified range slice content GetRange Start Key STOP # 3. Starting index, value replaces the original content SetRange Key index value # 4. value of additional spliced value
# Integer operations INCRBY key step size (value + ?) DECRBY Key steps (value - ?) INCR Key: + 1 operation DECR Key: - 1 Operation # scenarios: someone follows you on vibrato, is not it can be used INCR then, if attention is not canceled can DECR # floating-point operations: the first type to digital, and then to add and subtract, you can not use the append incrbyfloat the STEP Key
127.0.0.1:6379> mset wang:email [email protected] guo:email [email protected] OK 127.0.0.1:6379> mget wang:email guo:email 1) "[email protected]" 2) "[email protected]" 127.0.0.1:6379>
# Key value, in Principle 1 , Key value not too long, memory consumption, and the key to find such a high computational cost in the data 2 , should not be too short, poor readability # value 1, a string type the value of the content can store up to 512M
string Command Summary
# String operations . 1 , SET value Key 2 , Key SET value NX . 3 , GET Key . 3 , MSET . 4 , mget . 5 , SET Key seconds The value EX . 6 , strlen Key # digital operation . 7 , step incrby Key . 8 , step decrby Key long . 9 , incr Key 10 , Key DECR . 11, incrbyfloat Key number # (number may be positive or negative) # set expiration time in two ways # manner a 1, set key value. 3 EX # mode two . 1 , sET Key value 2, The expire. 5 Key # s 3, pexpire key 5 # Ms # view survival ttl Key # delete expired the persist Key # returns the old value and the new value is set (if the key does not exist, it is created and assigned) getset Key value
General command applies to all data types
# Switch library (value number of digital db0-db15 between 0-15) the SELECT number # View keys keys * keys expressions * # keys * keys user * (the beginning of the user key) # key to type the TYPE Key # key is present key EXISTS # delete key del key # key to rename the rename key newkey # Clear all the data in the current library (caution) flushdb # Clear all the libraries in all the data (caution) flushall
Exercise:
1, the library to view all the keys db0
SELECT 0
Keys *
2, provided bonds trill: username user001 corresponding value, and see
SET trill: username 'user001'
. 3, obtaining trill: username length value
strlen trill: username
. 4, disposable set trill: password, trill: gender, trill: fansnumber and view (custom value)
MSET TRILL: password '123456' TRILL: Gender 'm' TRILL: 10 fansnumber
mget TRILL: password TRILL: TRILL Gender: fansnumber
. 5, View key trill: score the existence of
eXISTS trill: score
6, an increase of 10 fans
incrby the TRILL: fansnumber 10
7, increased by 2 fans (one by one plus)
incr the TRILL: fansnumber
incr the TRILL: fansnumber
8, there are three fans unfollowed you the
decrby the TRILL: fansnumber 3
9, fans have a concern you cancel the
DECR the TRILL: fansnumber
10, thinking, thinking, thinking ..., clear the current library
flushdb
11, after ten thousand thinking, clear all libraries
flushall