# TS.RETENTION

> Change how long a time series keeps its samples.

URL: https://docs.hotkv.com/commands/ts-retention/

```
TS.RETENTION key milliseconds
```

- Group: Time series
- Complexity: O(M), M being the samples dropped
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the time-series license feature

`TS.RETENTION` sets the retention period of the time series `key`. Samples
older than `milliseconds` before the server's current time are dropped at
once, and again each time a sample is added. `0` keeps samples forever.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Set | Simple string `OK` | Simple string `OK` |

Error replies: `ERR series not found`, `ERR invalid retention value` for a
value that is not a non-negative integer, and `NOLICENSE ...` without the
`time-series` license feature.

## Examples

```
127.0.0.1:6379> TS.CREATE temp:kitchen
OK
127.0.0.1:6379> TS.RETENTION temp:kitchen 86400000
OK
127.0.0.1:6379> TS.RETENTION temp:garage 86400000
(error) ERR series not found
```

## Compatibility

HotKV-only command. RedisTimeSeries changes retention with `TS.ALTER`.

## See also

[TS.CREATE](https://docs.hotkv.com/commands/ts-create/index.md), [TS.INFO](https://docs.hotkv.com/commands/ts-info/index.md)