Redis - Keys Rename Command


Advertisements

Redis RENAME command is used to change the name of a key.

Return Value

String reply OK or error.

It returns an error if the old key and the new key names are equal, or when the key does not exist. If the new key already exists, then it overwrites the existing key.

Syntax

Following is the basic syntax of Redis RENAME command.

redis 127.0.0.1:6379> RENAME OLD_KEY_NAME NEW_KEY_NAME 

Example

First, create some keys in Redis and set some values in it.

redis 127.0.0.1:6379> SET tutorial1 redis 
OK 

Now, rename the key ‘tutorial1’ to ‘new-tutorial’.

redis 127.0.0.1:6379> RENAME tutorial1 new-tutorial 
OK 
redis_keys.htm
Advertisements