Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Renamenx Command

Redis Renamenx Command

Redis Key

The Redis Renamenx command is used to modify the name of a key only if the new key does not exist.

Syntax

The basic syntax of the redis Renamenx command is as follows:



redis 127.0.0.1:6379> RENAMENX OLD_KEY_NAME NEW_KEY_NAME

Available Version

= 1.0.0

Return Value

Returns 1 on success. Returns 0 if NEW_KEY_NAME already exists.

Example



# newkey does not exist, rename successful



redis> SET player "MPlyaer"

OK



redis> EXISTS best_player

(integer) 0



redis> RENAMENX player best_player

(integer) 1





# if newkey exists, fail



redis> SET animal "bear"

OK



redis> SET favorite_animal "butterfly"

OK



redis> RENAMENX animal favorite_animal

(integer) 0



redis> get animal

"bear"



redis> get favorite_animal

"butterfly"

Redis Key