LSET(3valkey)
π 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:
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)ltrim(3valkey)rpop(3valkey)rpoplpush(3valkey)rpush(3valkey)rpushx(3valkey)
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
- 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