Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Keys

Redis Keys

Redis key commands are used to manage the keys in redis.

Syntax

The basic syntax of Redis key commands is as follows:



redis 127.0.0.1:6379> COMMAND KEY_NAME

Example



redis 127.0.0.1:6379> SET runoobkey redis

OK

redis 127.0.0.1:6379> DEL runoobkey

(integer) 1

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


Redis keys Commands

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

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

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