in Redis, we can also directly operate on key, the following are the main commands we use:
(1) Keypattern it means to get all the keys that match the pattern, and it's important to note that we should avoid using this command because the command is time-consuming for large databases and the performance hit on Redis servers is relatively large. It supports Glob-style wildcard format, such as using * for any one or more characters, with the? Represents any character, using [XYZ] to denote any one of the letters in square brackets.
(2) Del key .... It removes the keys specified in the parameter from the database and is ignored if the specified key does not exist. Also, we need to point out that if the data type associated with a key is not a string type, but a list, set, hash, Sorted-set, and so on, the time complexity of deleting each key is O (M), where M represents the number of elements in the container. For a string type key, the time complexity is O (1).
(3) exists key determines whether the specified key exists. A return of 1 means that there is a return of 0 that does not exist.
(4) Move key DB 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. The move succeeds returns 1, otherwise it returns 0.
(5) Rename key Newkey It is renamed for the specified key, and if the command of the two key in the parameter is the same, or if the original key does not exist, then the command returns the relevant error message. If the newkey already exists, it will be overwritten directly.
(6) Renamenx key Newkey If the new value does not exist, the original value in the parameter is modified to the new value and is not overwritten if the new value exists.
(7) Persist key if the key has an expiration time, the command will eliminate its expiration time, so that the key no longer has a timeout, but can persist the storage.
(8) Expire key seconds This command sets the number of seconds to timeout for the key specified in the parameter, after which the key is automatically deleted, and if the key is modified before the time-out, the timeout associated with the key is removed.
(9) The TTL key gets the number of time-out seconds remaining for the key.
Randomkey randomly returns a key from the currently open database.
(one) Type key gets the type that is associated with the specified key in the parameter, and the command is returned in the form of a string.
Sort key The command is a bit complicated, it can be followed by a lot of other modifiers. Its function is to return the sorted original list.
Sinsing analysis of key-related commands in Redis