LSET key index element

Available since 1.0.0.

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 value

Simple string reply

*Examples

redis> RPUSH mylist "one"

  1. (integer) 1

redis> RPUSH mylist "two"

  1. (integer) 2

redis> RPUSH mylist "three"

  1. (integer) 3

redis> LSET mylist 0 "four"

  1. "OK"

redis> LSET mylist -2 "five"

  1. "OK"

redis> LRANGE mylist 0 -1

  1. 1) "four"
  2. 2) "five"
  3. 3) "three"
redis>