RPUSHX(3valkey)
π RPUSHX β the "only if you already exist" list push π
okay so bestie, welcome to rpushx(3valkey), straight out of the Valkey Command Manual β¨ this one's a little diva of a command: it appends one or more elements to a list, but only when the list is already there. no list, no push, no drama. π
β¨ NAME β¨
rpushx β appends one or more elements to a list only when the list exists. like, it's giving "i'll show up but only if the party's already happening" π
πΈ SYNOPSIS πΈ
RPUSHX key element [element...]
π¦ DESCRIPTION π¦
So here's the tea π β RPUSHX inserts the values you give it at the tail of the list stored at key, but only if key already exists and holds a list. That's the whole vibe check.
And listen, this is the important part: in contrary to valkey-rpush(7) RPUSH, no operation will be performed when key does not yet exist. Not a "hmm maybe", not a "let me create one for you" β literally nothing happens. it's giving unbothered. π
π REPLY π
valkey-protocol(7) Integer reply: the length of the list after the push operation. so like, a number, bestie. the new count. π
β 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, no cap π₯
π ACL CATEGORIES π
@fast@list@write
three little badges, iconic behavior β¨
π HISTORY π
- Available since: 2.2.0 β she's been around a minute π°οΈ
- Changed in 4.0.0: Accepts multiple element arguments. glow-up era π¦
π EXAMPLES π
watch her work:
127.0.0.1:6379> RPUSH mylist "Hello"
(integer) 1
127.0.0.1:6379> RPUSHX mylist "World"
(integer) 2
127.0.0.1:6379> RPUSHX myotherlist "World"
(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 how mylist existed so RPUSHX was like "say less" and gave us 2, but myotherlist was not a thing so she returned 0 and that list stayed a whole empty array? π that's the entire personality of this command right there. periodt.
π«Ά 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)lpushx(3valkey)lrange(3valkey)lrem(3valkey)lset(3valkey)ltrim(3valkey)rpop(3valkey)rpoplpush(3valkey)rpush(3valkey)
the whole list-command friend group, iykyk π
lowkey reminder: ifkeydoesn't exist,RPUSHXdoes absolutely nothing. don't come crying to me when your list is still missing. π
okay that's the page bestie, go forth and push responsibly π this was Valkey 9.0.0, dated 2025-10-21 β mwah, bye! π§β¨
π¦ 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