Easy Tutorial
❮ Pub Sub Subscribe Server Client Pause ❯

Redis Keys

Redis key commands are used to manage keys in Redis.

Syntax

The basic syntax for Redis key commands is as follows:

redis 127.0.0.1:6379> COMMAND KEY_NAME

Example

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

In the above example, DEL is a command and tutorialprokey is a key. If the key is successfully deleted, the command outputs (integer) 1, otherwise it outputs (integer) 0.


Redis Keys Commands

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

Number Command and Description
1 DEL key <br>This command deletes the key if it exists.
2 DUMP key <br>Serializes the given key and returns the serialized value.
3 EXISTS key <br>Checks if the given key exists.
4 EXPIRE key <br>Sets the expiration time for the given key in seconds.
5 EXPIREAT key timestamp <br>Similar to EXPIRE, but it sets the expiration time using a UNIX timestamp.
6 PEXPIRE key milliseconds <br>Sets the expiration time for the key in milliseconds.
7 PEXPIREAT key milliseconds-timestamp <br>Sets the expiration timestamp for the key in milliseconds.
8 KEYS pattern <br>Finds all keys matching the given pattern.
9 MOVE key db <br>Moves the key from the current database to the specified database.
10 PERSIST key <br>Removes the expiration from the key, making it persistent.
11 PTTL key <br>Returns the remaining expiration time of the key in milliseconds.
12 TTL key <br>Returns the remaining time to live of the key in seconds.
13 RANDOMKEY <br>Returns a random key from the current database.
14 RENAME key newkey <br>Renames the key.
15 RENAMENX key newkey <br>Renames the key only if the new key does not exist.
16 SCAN cursor [MATCH pattern] [COUNT count] <br>Iterates over the database keys.
17 TYPE key <br>Returns the type of the value stored at the key.

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

❮ Pub Sub Subscribe Server Client Pause ❯