English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Redis Rename command is used to modify the name of the key.
The basic syntax of the redis Rename command is as follows:
redis 127.0.0.1:6379> RENAME OLD_KEY_NAME NEW_KEY_NAME
>= 1.0.0
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. When NEW_KEY_NAME already exists, the RENAME command will overwrite the old value.
# The key exists and the newkey does not exist
redis> SET message "hello world"
OK
redis> RENAME message greeting
OK
redis> EXISTS message # message no longer exists
&40;integer&41; 0
redis> EXISTS greeting # greeting takes the place of
&40;integer&41; 1
# When the key does not exist, an error is returned
redis> RENAME fake_key never_exists
&40;error&41; ERR no such key
# newkey already exists, RENAME will overwrite the old newkey
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 # The original value dell has been overwritten
"lenovo"