Latest web development tutorials

comando Redis Rename

chave Redis (key)

Redis comando Rename é usado para modificar os nomes de chave.

gramática

Redis comandar Mudar sintaxe básica é a seguinte:

redis 127.0.0.1:6379> RENAME OLD_KEY_NAME NEW_KEY_NAME

versões disponíveis

> = 1.0.0

Valor de retorno

Ao renomear o sucesso solicitado OK, falha quando um erro é retornado.

Quando OLD_KEY_NAME mesma NEW_KEY_NAME ou OLD_KEY_NAME não existe, é devolvido um erro. Quando NEW_KEY_NAME já existe, RENAME comando substitui o valor antigo.

Exemplos

# 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"

chave Redis (key)