UK[?ri:?ne?m] US[?ri??ne?m]
vt. Rename..., change its name
Third person singular: renames Present participle: renaming Past tense: renamed Past participle: renamed
redis RENAME command syntax
Function:Rename key to newkey. When key and newkey are the same, or key does not exist, an error is returned. When newkey already exists, the RENAME command will overwrite the old value.
Syntax: RENAME key newkey
Available versions: >= 1.0.0
Time complexity : O(1)
Return: It will prompt OK when the name change is successful, and an error will be returned when it fails.
redis RENAME command example
# key 存在且 newkey 不存在 redis> SET message "hello world" OK redis> RENAME message greeting OK redis> EXISTS message # message 不復存在 (integer) 0 redis> EXISTS greeting # greeting 取而代之 (integer) 1 # 當 key 不存在時,返回錯誤 redis> RENAME fake_key never_exists (error) ERR no such key # newkey 已存在時, RENAME 會覆蓋舊 newkey redis> SET pc "lenovo" OK redis> SET personal_computer "dell" OK redis> RENAME pc personal_computer OK redis> GET pc (nil) redis:1> GET personal_computer # 原來的值 dell 被覆蓋了 "lenovo"