Redis keys commands are used for managing keys in Redis. Following is the syntax for using redis keys commands.




redis> SET tutorialspoint redis 
redis> DEL tutorialspoint 
(integer) 1

In the above example, DEL is the command, while tutorialspoint is the key. If the key is deleted, then the output of the command will be (integer) 1, otherwise it will be (integer) 0.

Redis Keys Commands

Following table lists some basic commands related to keys.

Sr.NoCommand & Description
1DEL keyThis command deletes the key, if it exists.
2DUMP keyThis command returns a serialized version of the value stored at the specified key.
3EXISTS keyThis command checks whether the key exists or not.
4EXPIRE key secondsSets the expiry of the key after the specified time.
5EXPIREAT key timestampSets the expiry of the key after the specified time. Here time is in Unix timestamp format.
6PEXPIRE key millisecondsSet the expiry of key in milliseconds.
7PEXPIREAT key milliseconds-timestampSets the expiry of the key in Unix timestamp specified as milliseconds.
8KEYS patternFinds all keys matching the specified pattern.
9MOVE key dbMoves a key to another database.
10PERSIST keyRemoves the expiration from the key.
11PTTL keyGets the remaining time in keys expiry in milliseconds.
12TTL keyGets the remaining time in keys expiry.
13RANDOMKEYReturns a random key from Redis.
14RENAME key newkeyChanges the key name.
15RENAMENX key newkeyRenames the key, if a new key doesn’t exist.
16TYPE keyReturns the data type of the value stored in the key.

Leave a Reply

Your email address will not be published. Required fields are marked *