LSET(3valkey)

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

πŸ’– LSET(3valkey) β€” the Valkey Command Manual, but make it a group chat πŸ’–

okay bestie, welcome to the LSET page of the Valkey Command Manual β€” yes, that's LSET(3valkey), and yes, we're about to make indexed list editing feel like a personality trait. ✨


🌸 NAME 🌸

lset β€” sets the value of an element in a list by its index. it's giving "surgical little edit to exactly one spot" and honestly? iconic. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

LSET key index element

three args, zero drama. periodt. πŸ’…


✨ DESCRIPTION ✨

so basically, LSET sets the list element at index to element. that's it, that's the whole vibe. 🫢

for the tea on how the index argument actually behaves, go peek at valkey-lindex(7) LINDEX β€” it's the same index energy, iykyk.

⚠️ real talk: an error is returned for out of range indexes. no silent nonsense, no "close enough", it will simply not. πŸ’€

πŸ’Œ REPLY πŸ’Œ

valkey-protocol(7) Simple string reply: OK.

that's it. a little OK and it's done. main character minimalism. πŸ‘‘


πŸ”₯ COMPLEXITY πŸ”₯

O(N) where N is the length of the list.

but bestie β€” setting either the first or the last element of the list is O(1). so the edges are cheap and the middle is a little trek. 🌈


πŸ‘‘ ACL CATEGORIES πŸ‘‘

  • @list
  • @slow
  • @write

yes she's slow in the middle, and yes she writes. own it. πŸ’œ


πŸ•°οΈ HISTORY πŸ•°οΈ

  • Available since: 1.0.0 β€” an absolute elder, a legend, been here since the beginning fr fr. ⭐

πŸ“ EXAMPLES πŸ“

watch her work:

127.0.0.1:6379> RPUSH mylist "one"
(integer) 1
127.0.0.1:6379> RPUSH mylist "two"
(integer) 2
127.0.0.1:6379> RPUSH mylist "three"
(integer) 3
127.0.0.1:6379> LSET mylist 0 "four"
OK
127.0.0.1:6379> LSET mylist -2 "five"
OK
127.0.0.1:6379> LRANGE mylist 0 -1
1) "four"
2) "five"
3) "three"

not me clocking that LSET mylist -2 "five" sniped the second-from-the-end slot and left "three" untouched. negative indexes stay winning. πŸ˜­πŸ’–


🌈 SEE ALSO 🌈

the whole friend group, all here, all valid:


and that's the whole page bestie πŸ’… mwah. this lil masterpiece is from Valkey 9.0.0, dated 2025-10-21, and it lives at LSET(3valkey). go set some elements, you absolute icon. πŸ§šπŸ’–

πŸ“¦ where this page comes from