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

string
required
The key of the list.
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).
TData
required
The new value to set at the specified index.

Return Value

'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