Redis Key

Redis keys commands are used for managing keys in redis. Syntax for using redis keys commands is shown below:

Syntax

redis 127.0.0.1:6379> COMMAND KEY_NAME

Example

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

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

Redis keys commands

Below given table shows some basic commands related to keys :-

S.N. Command & Description
1

DEL key
This command deletes the key, if exists

redis 127.0.0.1:6379> DEL KEY_NAME
2

DUMP key
This command returns a serialized version of the value stored at the specified key.

redis 127.0.0.1:6379> DUMP KEY_NAME
3

EXISTS key
This command checks whether the key exists or not.

redis 127.0.0.1:6379> EXISTS KEY_NAME
4

EXPIRE key seconds
Expires the key after the specified time

redis 127.0.0.1:6379> Expire KEY_NAME TIME_IN_SECONDS
5

EXPIREAT key timestamp
Expires the key after the specified time. Here time is in Unix timestamp format

redis 127.0.0.1:6379> Expireat KEY_NAME TIME_IN_UNIX_TIMESTAMP
6

PEXPIRE key milliseconds
Set the expiry of key in milliseconds

redis 127.0.0.1:6379> PEXPIRE KEY_NAME TIME_IN_MILLISECONDS
7

PEXPIREAT key milliseconds-timestamp
Set the expiry of key in unix timestamp specified as milliseconds

redis 127.0.0.1:6379> PEXPIREAT KEY_NAME TIME_IN_MILLISECONDS_IN_UNIX_TIMESTAMP
8

KEYS pattern
Find all keys matching the specified pattern

redis 127.0.0.1:6379> KEYS PATTERN
9

MOVE key db
Move a key to another database

redis 127.0.0.1:6379> MOVE KEY_NAME DESTINATION_DATABASE
10

PERSIST key
Remove the expiration from the key

redis 127.0.0.1:6379> PERSIST KEY_NAME
11

PTTL key
Get the remaining time in keys expiry in milliseconds.

redis 127.0.0.1:6379> PTTL KEY_NAME
12

TTL key
Get the remaining time in keys expiry.

redis 127.0.0.1:6379> TTL KEY_NAME
13

RANDOMKEY
Return a random key from redis

redis 127.0.0.1:6379> RANDOMKEY
14

RENAME key newkey
Change the key name

redis 127.0.0.1:6379> RENAME OLD_KEY_NAME NEW_KEY_NAME
15

RENAMENX key newkey
Rename key, if new key doesn't exist

redis 127.0.0.1:6379> RENAMENX OLD_KEY_NAME NEW_KEY_NAME
16

TYPE key
Return the data type of value stored in key.

redis 127.0.0.1:6379> TYPE KEY_NAME 

Loading ...

Related Results :

  1. Redis Key
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author