GETSET

Since 1.1.0Strings

Syntax

GETSET key value
  • Flags: fast, write
  • ACL categories: @fast, @string, @write
  • Arity: 3

Sets key to value and returns the value it held before, in one step. The key's expiry is removed. SET key value GET does the same.

Reply

  • The old value, or nil if the key did not exist.
  • A WRONGTYPE error if the key holds another type; the key is left as it was.

Examples

> SET a 1
OK
> GETSET a new
"1"
> GET a
"new"

Before 1.2, GETSET of a key of another type replaced it with the string and then replied WRONGTYPE.