Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

LPUSHX

Last updated
LPUSHX key element [element ...]
Group
List
Complexity
O(1) for each element added
Arity
-3 (at least 3 words, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

LPUSHX works like LPUSH, but only when key already holds a list. If the key does not exist, nothing is created and nothing is pushed.

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

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

127.0.0.1:6379> LPUSHX queue a
(integer) 0
127.0.0.1:6379> LPUSH queue a
(integer) 1
127.0.0.1:6379> LPUSHX queue b c
(integer) 3
127.0.0.1:6379> LRANGE queue 0 -1
1) "c"
2) "b"
3) "a"

Same as Redis 7.4 and Valkey 8.

LPUSH, RPUSHX, LRANGE