RPUSHX(3valkey)

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

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

  1. Available since: 2.2.0 β€” she's been around a minute πŸ•°οΈ
  2. 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 🫢

the whole list-command friend group, iykyk πŸ’œ


lowkey reminder: if key doesn't exist, RPUSHX does 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