LSET

Syntax

  1. LSET key index element

Time complexity: O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1).

Sets the list element at index to element. For more information on the index argument, see LINDEX.

An error is returned for out of range indexes.

Return

Simple string reply

Examples

  1. dragonfly> RPUSH mylist "one"
  2. (integer) 1
  3. dragonfly> RPUSH mylist "two"
  4. (integer) 2
  5. dragonfly> RPUSH mylist "three"
  6. (integer) 3
  7. dragonfly> LSET mylist 0 "four"
  8. "OK"
  9. dragonfly> LSET mylist -2 "five"
  10. "OK"
  11. dragonfly> LRANGE mylist 0 -1
  12. 1) "four"
  13. 2) "five"
  14. 3) "three"