The content of this article is about how to operate the key command in redis. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
redis command operation on key
Function: This command is used to delete one key or multiple keys when the key exists
Return value: If the key does not exist, the return value is 0. If the key exists, you will delete it. Number of success
Function: serialize given key
Return value: Return the serialized value
Function: Detect whether the key exists
Return value: Returns 1 if it exists, 0 if it does not exist
Function: Set the expiration time for key1 to 10 seconds
Return value: Return 1 if the setting is successful, and the value corresponding to the key taken out after expiration is nil
Function: Set expiration for key1 The time is 10 milliseconds
Return value: 1 is returned if the setting is successful. The value corresponding to the key taken out after expiration is nil
pexpireat key milliseconds -timestamp
|
Function: Set the timestamp of key expiration, one millisecond timer
keys pattern
|
redis 127.0.0.1:6379> SET w3c1 redis
OK
redis 127.0.0.1:6379> SET w3c2 mysql
OK
redis 127.0.0.1:6379> SET w3c3 mongodb
OK
redis 127.0.0.1:6379> KEYS w3c* 1) "w3c3"
2) "w3c1"
3) "w3c2"
Copy after login
Function: Find all keys that match the given pattern (pattern)
#Function: Set the key to be permanently valid
Function: Move the current database to the database db
Return value: Return 1 successfully, Returns 0 on failure
Function: in milliseconds Return the remaining expiration time of the key
Note: ttl key returns the remaining expiration time in seconds
##randomkey |
Function: Randomly return a database from the current database
Return value:
rename key newkey |
Function: Modify the name of the key to newkey
Return value: Return ok successfully
##renamenx key newkey | # newkey 不存在,改名成功
redis> SET player "MPlyaer"
OK
redis> EXISTS best_player
(integer) 0
redis> RENAMENX player best_player
(integer) 1
# newkey存在时,失败
redis> SET animal "bear"
OK
redis> SET favorite_animal "butterfly"
OK
redis> RENAMENX animal favorite_animal
(integer) 0
redis> get animal "bear"
redis> get favorite_animal "butterfly"
Copy after login
Function: Only when the key does not exist, rename the key to newkey
type key |
Function: Return the value type stored in key
The above is the detailed content of How to operate key commands in redis. For more information, please follow other related articles on the PHP Chinese website!