# RPUSHX

> Append elements to the tail of a list, only if the list already exists.

URL: https://docs.hotkv.com/commands/rpushx/

```
RPUSHX key element [element ...]
```

- Group: List
- Complexity: O(1) for each element added
- HotKV Cloud: all plans
- On-Premise: no license needed

`RPUSHX` works like [RPUSH](https://docs.hotkv.com/commands/rpush/index.md), but only when `key` already
holds a list. If the key does not exist, nothing is created and nothing is
pushed.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| List exists | Integer: the length of the list after the push | Same |
| Key does not exist | Integer `0` | Same |

`RPUSHX` replies with a `WRONGTYPE` error if `key` holds a value that is not a
list.

## Examples

```
127.0.0.1:6379> RPUSHX queue a
(integer) 0
127.0.0.1:6379> RPUSH queue a
(integer) 1
127.0.0.1:6379> RPUSHX queue b c
(integer) 3
127.0.0.1:6379> LRANGE queue 0 -1
1) "a"
2) "b"
3) "c"
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[RPUSH](https://docs.hotkv.com/commands/rpush/index.md), [LPUSHX](https://docs.hotkv.com/commands/lpushx/index.md), [LRANGE](https://docs.hotkv.com/commands/lrange/index.md)