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"