Redis Keys

Redis key commands are used to manage Redis keys.

Syntax

The basic syntax of Redis key commands is as follows:

redis 127.0.0.1:6379> COMMAND KEY_NAME

Examples

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

In the above example,DELis a command,examplekeyis a key.(integer) 1If the key is deleted successfully, the output after executing the command is(integer) 0


Redis Keys Commands

Redis Keys Commands

No.Command and Description
1DEL key
This command deletes a key when it exists.
2DUMP key
Serialize the given key and return the serialized value.
3EXISTS key
Check whether the given key exists.
4EXPIRE key seconds
Set an expiration time for the given key, in seconds.
5EXPIREAT key timestamp
The effect of EXPIREAT is similar to EXPIRE; both are used to set an expiration time for a key. The difference is that the time parameter accepted by the EXPIREAT command is a UNIX timestamp.
6PEXPIRE key milliseconds
Set the expiration time of a key in milliseconds.
7PEXPIREAT key milliseconds-timestamp
Set the timestamp (unix timestamp) of the key expiration time in milliseconds.
8KEYS pattern
Find all keys matching the given pattern.
9MOVE key db
Move a key from the current database to the given database db.
10PERSIST key
Remove the expiration time of a key; the key will be kept permanently.
11PTTL key
Return the remaining expiration time of a key in milliseconds.
12TTL key
Return the remaining time to live (TTL) of the given key in seconds.
13RANDOMKEY
Return a random key from the current database.
14RENAME key newkey
Change the name of a key
15RENAMENX key newkey
Rename the key to newkey only when newkey does not exist.
16SCAN cursor [MATCH pattern] [COUNT count]
Iterate over the keys in the database.
17TYPE key
Return the type of the value stored in the key.

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

Other Extensions