English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Rename command

Clave (key) de Redis

The Redis Rename command is used to modify the name of the key.

Syntax

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

redis 127.0.0.1:6379> RENAME OLD_KEY_NAME NEW_KEY_NAME

Available version

>= 1.0.0

Return value

Prompt OK when the rename is successful, and return an error when it fails.

When OLD_KEY_NAME and NEW_KEY_NAME are the same, or OLD_KEY_NAME does not exist, an error is returned. Cuando NEW_KEY_NAME ya existe, el comando RENAME reemplazará el valor antiguo.

Ejemplo en línea

# La clave existe y newkey no existe

redis> SET message "hello world"
OK

redis> RENAME message greeting
OK

redis> EXISTS message # message ya no existe
&40;entero&41; 0

redis> EXISTS greeting # greeting lo reemplazará
&40;entero&41; 1


# Al no existir la clave, se devuelve un error

redis> RENAME fake_key never_exists
&40;error&41; ERR clave no encontrada


# newkey ya existe, RENAME reemplazará el valor antiguo

redis> SET pc "lenovo"
OK

redis> SET personal_computer "dell"
OK

redis> RENAME pc personal_computer
OK

redis> GET pc
&40;nil&41;

redis:1> GET personal_computer # El valor original dell ha sido reemplazado
"lenovo"

Clave (key) de Redis