LPUSHX(3valkey)
π LPUSHX β the manual page (valkey, section 3valkey) π
okay bestie, sit down, hydrate, because we're talking about LPUSHX and it's literally the chill, low-commitment cousin of LPUSH. π«Ά
β¨ NAME β¨
lpushx β prepends one or more elements to a list, but ONLY when the list actually exists. no list, no push, no drama. π
β¨ SYNOPSIS β¨
LPUSHX key element [element...]
β¨ DESCRIPTION β¨
so the vibe is: this command inserts the values you give it at the head of the list stored at key β but only if key already exists and holds a list. π¦
and here's the key difference, the part where it's giving responsible: unlike valkey-lpush(7) LPUSH, no operation will be performed when key does not yet exist. like, it just says "not my problem" and does nothing. iconic honestly. πΈ
β¨ REPLY β¨
valkey-protocol(7) Integer reply: the length of the list after the push operation. β
β¨ COMPLEXITY β¨
O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments. fast fast fast fr fr π₯
β¨ ACL CATEGORIES β¨
@fast @list @write
β¨ HISTORY β¨
- Available since:
2.2.0π - Changed in
4.0.0: Accepts multiple element arguments. π
β¨ EXAMPLES β¨
bestie watch this, the whole personality of the command in five lines:
127.0.0.1:6379> LPUSH mylist "World"
(integer) 1
127.0.0.1:6379> LPUSHX mylist "Hello"
(integer) 2
127.0.0.1:6379> LPUSHX myotherlist "Hello"
(integer) 0
127.0.0.1:6379> LRANGE mylist 0 -1
1) "Hello"
2) "World"
127.0.0.1:6379> LRANGE myotherlist 0 -1
(empty array)
see?? mylist existed so the push went through and it returned 2. myotherlist did NOT exist, so it returned 0 and... nothing happened. no list materialized out of thin air. the LRANGE says (empty array). it said nope. π (affectionately)
β¨ SEE ALSO β¨
blmove(3valkey), blmpop(3valkey), blpop(3valkey), brpop(3valkey), brpoplpush(3valkey), lindex(3valkey), linsert(3valkey), llen(3valkey), lmove(3valkey), lmpop(3valkey), lpop(3valkey), lpos(3valkey), lpush(3valkey), lrange(3valkey), lrem(3valkey), lset(3valkey), ltrim(3valkey), rpop(3valkey), rpoplpush(3valkey), rpush(3valkey), rpushx(3valkey)
the whole list family, all linked, all slaying. go read them, iykyk. πβ¨
π and that's the whole page bestie, you understood it, i'm so proud of you.
this cutie patootie of a manpage is from valkey version 9.0.0, dated 2025-10-21. mwah. ππ§ββοΈ
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms