---
title: "GETSET"
url: "https://docs.yugabyte.com/stable/yedis/api/getset/"
---

# GETSET

## Synopsis

**`GETSET key value`**

This command is an atomic read and write operation that gets the existing value that is associated with the given `key` while rewriting it with the given `value`.

- If the given `key` does not exist, the given `value` is inserted for the `key`, and null is returned.
- If the given `key` is associated with non-string data, an error is raised.

## Return Value

Returns the old value of the given `key`.

## Examples

```sh
$ SET yugakey 1
```

```
"OK"
```

```sh
$ GETSET yugakey 2
```

```
1
```

## See also

[`append`](/stable/yedis/api/append/ "append"), [`get`](/stable/yedis/api/get/ "get"), [`getrange`](/stable/yedis/api/getrange/ "getrange"), [`incr`](/stable/yedis/api/incr/ "incr"), [`incrby`](/stable/yedis/api/incrby/ "incrby"), [`set`](/stable/yedis/api/set/ "set"), [`setrange`](/stable/yedis/api/setrange/ "setrange"), [`strlen`](/stable/yedis/api/strlen/ "strlen")
