GETSET key value

    Time complexity: O(1)

    Atomically sets to value and returns the old value stored at key. Returns an error when exists but does not hold a string value.

    redis> INCR mycounter

    redis> GETSET mycounter "0"

      redis>

      : the old value stored at , or nil when key did not exist.

      redis> SET mykey "Hello"

      1. "OK"

      redis> GET mykey

        redis>