Redis-key value operation
Next, there are some commonly used redis commands to learn, but some of them are disabled in our production environment, which will affect performance and do not meet the redis development specifications. You can search Ali redis development specifications for reference and study.
1Query the common keys of pattern.
In redis, fuzzy query key is allowed
There are three wildcards,?, []
: with any number of characters
?: with a single character
[]: a character in parentheses
127.0.0.1 purl 6379 > keys
1) "What"
127.0.0.1 purl 6379 > keys What
1) "What"
127.0.0.1 purl 6379 > get What
"laoyang"
127.0.0.1 purl 6379 > keys Wha
1) "What"
127.0.0.1 6379 > keys Wha [ty]
1) "What"
127.0.0.1 6379 > keys Wha?
1) "What"
2 the key key returns the random name of the
127.0.0.1 purl 6379 > set chief yuhao
OK
127.0.0.1 purl 6379 > randomkey
"chief"
127.0.0.1 purl 6379 > randomkey
"What"
3. Judge the type of key
127.0.0.1 purl 6379 > type chief
String
4. Judge whether key exists.
127.0.0.1 purl 6379 > exists chief
(integer) 1
Return 1 means it exists, 0 means it doesn't exist.
5,rename key
If key exists, the cover key will be overwritten
6 move key to move a key to another library
127.0.0.1 purl 6379 > keys
1) "yuhao"
2) "What"
127.0.0.1 move yuhao 6379 > 1
(integer) 1
127.0.0.1 purl 6379 > get yuhao
(nil)
127.0.0.1 purl 6379 > keys
1) "What"
7, expiration time-in seconds
Query validity period
127.0.0.1 purl 6379 > ttl What
(integer)-1 permanent validity is negative one
127.0.0.1 purl 6379 > get What
"laoyang"
127.0.0.1 expire What 6379 > set expiration for 5 seconds
(integer) 1
127.0.0.1 purl 6379 > get What
(nil)
127.0.0.1 6379 > keys *
(empty list or set)