LPUSHX(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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