English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Keys (key)

Redis key commands are used to manage keys in redis.

Syntax

The basic syntax of Redis key commands is as follows:

redis 127.0.0.1:6379> COMMAND KEY_NAME

Online examples

redis 127.0.0.1:6379> SET w3codeboxkey redis
OK
redis 127.0.0.1:6379> DEL w3codeboxkey
(integer) 1

In the above examples DEL It is a command, w3codeboxkey It is a key. If the key is deleted successfully, the command will output after execution (integer) 1Otherwise, it will output (integer) 0

Redis keys commands

The following table lists the basic commands related to Redis keys:

Serial numberCommand and description
1DEL key
This command is used to delete the key when the key exists.
2DUMP key
Serialize the given key and return the serialized value.
3EXISTS key
Check if the given key exists.
4EXPIRE key seconds
Set the expiration time for the given key, measured in seconds.
5EXPIREAT key timestamp
The function of EXPIREAT is similar to that of EXPIRE, both are used to set an expiration time for keys. The difference lies in that the EXPIREAT command accepts a time parameter in UNIX timestamp format.
6PEXPIRE key milliseconds
Sets the expiration time of the key in milliseconds.
7PEXPIREAT key milliseconds-timestamp
Sets the key's expiration time timestamp (unix timestamp) in milliseconds.
8KEYS pattern
Finds all keys that match the given pattern (pattern).
9MOVE key db
Moves the key in the current database to the specified database db.
10PERSIST key
Removes the expiration time of the key, and the key will be kept permanently.
11PTTL key
Returns the remaining expiration time of the key in milliseconds.
12TTL key
Returns the remaining time to live (TTL, time to live) of the given key in seconds.
13RANDOMKEY
Returns a random key from the current database.
14RENAME key newkey
Changes the name of the key.
15RENAMENX key newkey
Renames the key to newkey only if newkey does not exist.
16SCAN cursor [MATCH pattern] [COUNT count]
Iterates over the database keys in the database.
17TYPE key
Returns the type of the stored value of the key.

For more commands, please refer to:https://redis.io/commands