Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Redis Key


May 16, 2021 Redis


Table of contents


Redis Key

The Redis key command is used to manage the keys of the redis.

Grammar

The basic syntax of the Redis key command is as follows:

redis 127.0.0.1:6379> COMMAND KEY_NAME

Instance

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

In the above example, DEL is a command and w3ckey is a key. If the key is removed successfully, the command executes after output (integer) 1, otherwise output (integer) 0


Redis keys command

The following table gives the basic commands related to the Redis key:

Serial number Commands and descriptions
1 DEL key
This command is used to remove key when it exists.
2 DUMP key
Serialize a given key and return the serialized value.
3 EXISTS key
Check for the existence of a given key.
4 EXPIRE key seconds
Set an expiration time for a given key.
5 EXPIREAT key timestamp
EXPIREAT serves a similar purpose to EXPIRE and is used to set an expiration time for key. The difference is that the time parameter accepted by the EXPIREAT command is the UNIX timestamp.
6 PEXPIRE key milliseconds
Set the expiration time of key in milliseconds.
7 PEXPIREAT key milliseconds-timestamp
Set the timestamp for the key expiration time (unix timestamp) in milliseconds
8 KEYS pattern
Find all keys that match a given pattern.
9 MOVE key db
Move the key of the current database to a given database db.
10 PERSIST key
Remove the expiration time of the key, and the key will persist.
11 PTTL key
Returns the remaining expiration time of key in milliseconds.
12 TTL key
Returns the remaining time of life (TTL, time to live) for a given key in seconds.
13 RANDOMKEY
A key is returned randomly from the current database.
14 RENAME key newkey
Modify the name of the key
15 RENAMENX key newkey
Change the key name to newkey only if newkey does not exist.
16 TYPE key
Returns the type of value that key stores.

For more commands, please refer to: http://redis.readthedocs.org/en/latest/index.html