String of redis syntax introduction


String basic add, delete, modify and query commands:> set k1 v1
OK> get k1
"v1"> del k1
(integer) 1> get k1
(nil)> set k2 v2
OK > append K2 12dffsd // append the command
(integer) 9> get k2
"v212dffsd" > strlen K2 // returns the length of the corresponding value of the key
(integer) 9> get k2
"v212dffsd"> set k1 4
OK > incr K1 // increase 1 at a time to return the increased value
(integer) 5> get k1
"5" > decr K1 // decrease 1 at a time, and return the reduced value
(integer) 4 > incrby K1 4 // directly increase the following value
(integer) 8 > decrby K1 2 // directly reduce the later value
(integer) 6 > incr K2 // cannot operate on a value that is not a number
(error) ERR value is not an integer or out of range

Incr / decr / incrby / decrby can only operate on values that are numeric> get k2
"v212dffsd" > getrange K2 0 - 1 // returns the string between consecutive positions, including both sides
"v212dffsd"> getrange k2 03
(error) ERR wrong number of arguments for 'getrange' command> getrange k2 0 3
"v212" > setrange K2 0 XXX // replace characters with XXX from position 0
(integer) 9> get k2

Setex (set with expire) key second value / setnx (set if not exist)> setex k2 10 sss
OK> ttl k2
(integer) 6> setnx k1 44
(integer) 1> setnx k1 77
(integer) 0>

You can also batch set and get values through Mset and mget> mset k1 v1 k2 v2
OK> mget k1 k2
1) "v1"
2) "v2" > msetnx K3 V3 K4 V4 // all instructions are executed unsuccessfully
(integer) 1> msetnx k3 v33 k5 v5
(integer) 0> get k3

Recommended Today

PHP calls cjieba word segmentation through FFI

This paper attempts to use the FFI test of PHP 7.4 to directly call the dynamic library of cjieba word segmentation. The reason for choosing cjieba is that FFI uses the calling convention of C. If you use CPP, you have to wrap it yourself, and then use external C to let the compiler generate […]