command prototype |
Time complexity |
command description |
return value |
KEYS pattern |
o (n) |
pattern supports Glob-style wildcard formats, such as * for any one or more characters, for any character, and [ABC] to denote any letter in square brackets. |
matches the list of keys for the pattern. |
DEL key [key ...] |
O (N) |
N in time complexity means the number of keys deleted. Deletes the keys specified in the parameters from the database and ignores them directly if the specified key does not exist. Another point to note is that if the specified key is associated with a data type other than string type, but a container type such as list, set, hashes, and sorted set, the command deletes each key with a time complexity of O (M), where M represents the number of elements in the container. For a string type key, the time complexity is O (1). |
The number of keys that were actually deleted. |
EXISTS Key |
O (1) |
Determines whether the specified key exists. |
1 means presence, 0 means no. |
MOVE Key db |
O (1) |
Moves the key key specified in the current database to the database specified in the parameter. If the key already exists in the target database, or does not exist in the current database, the command does nothing and returns 0. |
Move successfully returns 1, otherwise 0. |
RENAME Key Newkey |
O (1) |
Renames the specified key, and returns the associated error message if the command for the two keys in the parameter is the same, or if the source key does not exist. If the newkey already exists, it is overwritten directly. |
|
Renamenx Key Newkey |
O (1) |
If the new value does not exist, the original value in the parameter is modified to the new value. Other conditions are consistent with rename. |
1 indicates that the modification succeeded, otherwise 0. |
PERSIST Key |
O (1) |
If the key has an expiration time, the command removes its expiration time so that the key no longer has a timeout, but can persist the store. |
1 means that the expiration time of key is moved out, and 0 indicates that the key does not exist or has no expiration time. |
EXPIRE key seconds |
O (1) |
The command sets the number of seconds to timeout for the key specified in the parameter, and after that time, the key is automatically deleted. If the key is modified before the time-out, the timeout associated with the key is removed. |
1 indicates that the timeout is set, and 0 indicates that the key does not exist or cannot be set. |
expireat key timestamp |
O (1) |
The logical function of the command is exactly the same as the expire, except that the time-out specified by the command is absolute, not relative. The time parameter is in the UNIX timestamp format, which is the number of seconds that flow through the beginning of January 1, 1970. |
1 indicates that the timeout is set, and 0 indicates that the key does not exist or cannot be set. |
TTL Key |
O (1) |
Gets the timeout description remaining for the key. |
Returns the remaining description, or 1 if the key does not exist or does not have a time-out setting. |
Randomkey |
O (1) |
Returns a key randomly from the currently open database. |
Returns the random key if the database is empty and returns nil. |
TYPE Key |
O (1) |
Gets the type of the value associated with the key specified in the parameter, which is returned in the form of a string. |
The strings returned are string, list, set, hash, and zset if key does not exist to return none. |
SORT key [by pattern] [LIMIT offset count] [get pattern [get pattern ...]] [asc| DESC] [ALPHA] [STORE destination] |
O (N+m*log (M)) |
This command is relatively complex, so we just give the most basic usage here, and interested netizens can refer to the official Redis documentation. |
Returns the original list after sorting. |