Redis – Keys

  • Post author:
  • Post category:Redis
  • Post comments:1 Comment

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

Syntax

redis 127.0.0.1:6379> COMMAND KEY_NAME

Example

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

In the above example, DEL is the command, while Adglob 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 https://adglob.in/blog/redis-keys-del-command/
command deletes the key, if it exists.
2DUMP keyThishttps://adglob.in/blog/redis-keys-dump-command/
command returns a serialized version of the value stored at the specified key.
3EXISTS keyThis https://adglob.in/blog/redis-keys-exists-command/
command checks whether the key exists or not.
4EXPIRE key https://adglob.in/blog/redis-keys-expire-command/
secondsSets the expiry of the key after the specified time.
5EXPIREAT key https://adglob.in/blog/redis-keys-expireat-command/
timestampSets the expiry of the key after the specified time. Here time is in Unix timestamp format.
6PEXPIRE key https://adglob.in/blog/redis-keys-pexpire-command/
millisecondsSet the expiry of key in milliseconds.
7PEXPIREAT key https://adglob.in/blog/redis-keys-pexpireat-command/
milliseconds-timestampSets the expiry of the key in Unix timestamp specified as milliseconds.
8KEYS patternFindshttps://adglob.in/blog/redis-keys-command/
all keys matching the specified pattern.
9MOVE key https://adglob.in/blog/redis-keys-move-command/
dbMoves a key to another database.
10PERSIST https://adglob.in/blog/redis-keys-persist-command/
keyRemoves the expiration from the key.
11PTTL keyGets https://adglob.in/blog/redis-keys-pttl-command/
the remaining time in keys expiry in milliseconds.
12TTL keyGets https://adglob.in/blog/redis-keys-ttl-command/
the remaining time in keys expiry.
13RANDOMKEYReturns https://adglob.in/blog/redis-keys-random-key-command/
a random key from Redis.
14RENAME key https://adglob.in/blog/redis-keys-rename-command/
newkeyChangesthe key name.
15RENAMENX key newkeyRenameshttps://adglob.in/blog/redis-keys-renamenx-command/
the key, if a new key doesn’t exist.
16TYPE keyReturns https://adglob.in/blog/redis-keys-type-command/
the data type of the value stored in the key.

This Post Has One Comment

Leave a Reply