LSET
LSET key index element
- Group
- List
- Complexity
- O(N) where N is the distance of the index from the nearer end
- Arity
- 4 (exactly, counting the command name)
- Flags
- write
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
LSET overwrites the element at position index of the list stored at key
with element. Indexes start at 0; negative indexes count from the end. The
list must exist and the index must be in range.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Simple string OK |
Same |
Errors:
ERR no such keyifkeydoes not exist.WRONGTYPEifkeyholds a value that is not a list.ERR value is not an integer or out of rangeifindexis not an integer.ERR index out of rangeif the list has no element atindex.
Examples
Section titled “Examples”127.0.0.1:6379> RPUSH letters a b c(integer) 3127.0.0.1:6379> LSET letters 1 "B"OK127.0.0.1:6379> LSET letters -1 "C"OK127.0.0.1:6379> LSET letters 9 "z"(error) ERR index out of range127.0.0.1:6379> LRANGE letters 0 -11) "a"2) "B"3) "C"Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.