# SET

> Set a key to hold a string value.

## Arguments

<ParamField body="key" type="string" required>
  The key
</ParamField>

<ParamField body="value" type="TValue" required>
  The value, if this is not a string, we will use `JSON.stringify` to convert it
  to a string.
</ParamField>

<ParamField body="opts" type="object">
You can pass a few options to the command.
<Expandable >

  <ParamField body="get" type="boolean">
    Instead of returning `"OK"`, this will cause the command to return the old
    value stored at key, or `null` when key did not exist.
  </ParamField>
  <ParamField body="ex" type="integer">
    Adds an expiration (in seconds) to the key.
  </ParamField>
  <ParamField body="px" type="integer">
    Adds an expiration (in milliseconds) to the key.
  </ParamField>
  <ParamField body="exat" type="integer">
    Expires the key after the given timestamp (in seconds).
  </ParamField>

  <ParamField body="pxat" type="integer">
    Expires the key after the given timestamp (in milliseconds).
  </ParamField>

  <ParamField body="keepTtl" type="boolean">
    Keeps the old expiration if the key already exists.
  </ParamField>

  <ParamField body="nx" type="boolean">
    Only set the key if it does not already exist.
  </ParamField>

  <ParamField body="xx" type="boolean">
    Only set the key if it already exists.
  </ParamField>

  

</Expandable>

</ParamField>

## Response

<ResponseField required>
  `"OK"`
</ResponseField>

<RequestExample>
```ts Basic
await redis.set("my-key", {my: "value"});
```

```ts Expire in 60 seconds
await redis.set("my-key", {my: "value"}, {
  ex: 60
});
```

```ts Only update
await redis.set("my-key", {my: "value"}, {
  xx: true
});
```
</RequestExample>
