Key Commands
Key commands are used to manage keys in Redis. These commands allow you to create, delete, check, and modify keys and their attributes, such as expiration time.
Command List
DEL
Deletes the specified key
EXISTS
Checks if one or more given keys exist
EXPIRE
Sets the expiration time for a given key (in seconds)
EXPIREAT
Sets the expiration timestamp for a given key (Unix timestamp in seconds)
KEYS
Finds all keys matching the given pattern
MOVE
Moves the specified key from the current database to the specified database
PERSIST
Removes the expiration time from a given key, making it persistent
PEXPIRE
Sets the expiration time for a given key (in milliseconds)
PEXPIREAT
Sets the expiration timestamp for a given key (Unix timestamp in milliseconds)
PTTL
Similar to the TTL command, but returns the remaining survival time of a key in milliseconds
RANDOMKEY
Randomly returns a key from the current database
RENAME
Renames a key to a new key
RENAMENX
Renames a key to a new key only if the new key does not exist
TTL
Returns the remaining survival time of a key (in seconds)
TYPE
Returns the type of value stored in a key
Use Cases
Key commands are among the most fundamental and important commands in Redis. They are used to manage the lifecycle of keys, including creating, querying, updating, and deleting keys. EXPIRE and TTL related commands are particularly suitable for caching scenarios, where expired data can be automatically cleaned up.
For detailed usage and parameters of each command, please refer to the individual command documentation linked above.