Redis Renamenx command
Redis Renamenx command is used to modify the key of the new key name does not exist.
grammar
redis Renamenx basic command syntax is as follows:
redis 127.0.0.1:6379> RENAMENX OLD_KEY_NAME NEW_KEY_NAME
Available versions
> = 1.0.0
return value
When modifying success, 1 is returned. If NEW_KEY_NAME already exists, 0 is returned.
Examples
# newkey 不存在,改名成功 redis> SET player "MPlyaer" OK redis> EXISTS best_player (integer) 0 redis> RENAMENX player best_player (integer) 1 # newkey存在时,失败 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"