Delkey1key2... keyn function: delete one or more keys. Return: Ignore nonexistent keys. Return the number of actually deleted keys. renamekeynewkey function: assign a new key name to the key. Note: if newkey already exists, the original newkey will be overwritten by renamenxkeynewkey. function: Rename the key
Del key1 key2... keyn function: delete one or more keys. Return: Ignore nonexistent keys. Return the number of actually deleted keys. rename key newkey function: assign a new key name to the key. Note: if newkey already exists, newkey will be overwritten by renamenx key newkey. function: Rename the key
del key1 key2 ... Keyn
Purpose: delete one or more keys.
Return Value: ignore a nonexistent key and return the number of actually deleted keys.
rename key newkey
Purpose: assign a new key name to the key.
NOTE: If newkey already exists, the original value of newkey is overwritten.
renamenx key newkey
Purpose: Rename the key as newkey.
Return: 1 is returned for modification. If no modification is made, 0 is returned.
Note: nx --> not exists, that is, when newkey does not exist, change the name.
move key db
redis 127.0.0.1:6379[1]> select 2OKredis 127.0.0.1:6379[2]> keys *(empty list or set)redis 127.0.0.1:6379[2]> select 0OKredis 127.0.0.1:6379> keys *1) "name"2) "cc"3) "a"4) "b"redis 127.0.0.1:6379> move cc 2(integer) 1redis 127.0.0.1:6379> select 2OKredis 127.0.0.1:6379[2]> keys *1) "cc"redis 127.0.0.1:6379[2]> get cc"3"
(Note: A redis process opens more than one database. By default, 16 databases are opened, ranging from 0 to 15,
If you want to open more databases, you can modify them from the configuration file)
Keys pattern query the corresponding key
Fuzzy key query is allowed in redis.
There are 3 wildcards *,? , []
*: Wildcard can contain any number of characters.
? : Wildcard Single Character
[]: A certain character in parentheses
redis 127.0.0.1:6379> flushdbOKredis 127.0.0.1:6379> keys *(empty list or set)redis 127.0.0.1:6379> mset one 1 two 2 three 3 four 4OKredis 127.0.0.1:6379> keys o*1) "one"redis 127.0.0.1:6379> key *o(error) ERR unknown command 'key'redis 127.0.0.1:6379> keys *o1) "two"redis 127.0.0.1:6379> keys ???1) "one"2) "two"redis 127.0.0.1:6379> keys on?1) "one"redis 127.0.0.1:6379> set ons yesOKredis 127.0.0.1:6379> keys on[eaw]1)"one"
Random keyexists key returned by randomkey
Checks whether the key exists and returns 1/0
type key
Type of the value stored in the key
String, link, set, order set, and hash
ttl key
Purpose: query the key lifecycle.
Return: seconds
Note:-1 is returned for non-existing or expired keys/non-expired keys.
In Redis2.8,-2 is returned for keys that do not exist.
Expire key integer value
Purpose: set the key lifecycle in seconds.
Likewise:
Pexpire key in milliseconds, set the lifecycle
Pttl key, returned in milliseconds
persist key
Purpose: set the specified key to permanently valid.