1>set set name Zhangsan:ok get Name:zhangsan set name Lisi:ok get Name:lisi 2> setnx If present, returns 0, does not overwrite the original value setnx n Ame lisi:0 get Name:lisi setnx age 15:1 get age:15 3> Setex if not present, new if present, overwrite (with new parameter valid time) Set 5 15:ok (no on how to return OK) get age:15 (disappears after 5S) 4>setrange set substring setrange name 1 a:4 (output name length) get Name:lasi setrange Name 1 b Cdef:6 (the length of the output name) get Name:lbcdef setrange name 6 t:7 (because the length is 6 in the position of the corner label 6 to add "T" character, will lengthen the string) get Name:lbcdeft
SetRange Name 9 ss:11 (starting with corner 9, adding "ss" string, length to one) get Name:lbcdeft\x00\x00\x00ss (padding by "\x00") i.e., if the string to be replaced is not long enough, replace The response length string, if too long, will be stitched back for the first time replaced with the i->a length unchanged the second time replaced the asi->bcdef length increase 5> mset batch setup Msetnx name Zhangsan name1 Lisi:ok (regardless of whether it exists or not, it will return OK, whether or not it will be assigned) use Setex to clear existing fields Setex name 1 1:oksetex age 1 1:ok 6>msetnx set the value of multiple keys at once, success returns OK means all values are set, failure returns 0 means no value is set, the original value is not overwritten msetnx name Zhangsan name1 Lisi:ok get Name:zhangsan get name1:lisi msetnx name Zhangsan1 name1 lisi1:07>get Get string contents 8>getset both get and set &NBSP;&NB Sp; getset Zhangsan1:zhangsan (returns the replaced content) 9>getrange get substring ex:getrange name 0 5 getrange Name 0 1:zh getrange name 0-1:zhangsan1 (-1 means get to string tail) getrange name 1-1:hangsan1 getrange name 0 15:zhangsan1 (15> Length 9, will also select all content, and will not be spliced with spaces or anything) getrange name 0 8:zhangsan1 (length 9, select 0-8, all content will be selected, the corner label starts from 0) getrange name 15-1: "" (empty string) GetRange Name 15 16: "" (empty string) 10>Mget returns the value of multiple keys at once if key does not exist return nil get name Name1:1) zhangsan1 2) Lisi get name Name2:1) zhangsan1 2) NIL&NBSP;&NBSP;11>INCR value + + operation INCR Name: <error> (now name=zhangsan1 not a number) set age 20:ok ge T age:20 incr age:21 (value returned after +1) get Age:21 12>incrby +x operation on value Incrby age 5:26 (value returned after +x) get age:26 &N BSP;13>DECR to value-the operation 14>decrby the-X operation on value 15>append append append name lisi:13 (9+4= 13, returns the length of the appended string) get Name:zhangsan1lisi 16>strlen get length
Tests for Redis action string