Skip to main content

Overview

Sets the list element at index to value. The index is zero-based. An error is returned for out of range indexes.

Method Signature

Parameters

key
string
required
The key of the list.
index
number
required
The index of the element to set (zero-based). Negative indices count from the end of the list (e.g., -1 is the last element, -2 is the second-to-last).
value
TData
required
The new value to set at the specified index.

Return Value

result
'OK'
Returns "OK" on success. Throws an error if the index is out of range or the key does not exist.

Examples

Basic Usage

Using Negative Indexes

Working with Objects

Error Handling

Updating Specific Fields

Batch Updates

Toggle Values

Replacing Queue Items

See Also

  • LINDEX - Get an element from a list by index
  • LRANGE - Get a range of elements from a list
  • LLEN - Get the length of a list
  • LPUSH - Insert elements at the head of a list