Redis Lset Command

Redis Lists(List)

Redis Lset sets the value of an element by index.

When the index parameter is out of range, or when LSET is performed on an empty list, an error is returned.

For more information about list indices, please refer toLINDEX command。

Syntax

The basic syntax of the redis Lset command is as follows:

redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE

Available Versions

>= 1.0.0

Return Value

Returns ok on success, otherwise returns an error message.

Example

redis 127.0.0.1:6379> RPUSH mylist "hello"
(integer) 1
redis 127.0.0.1:6379> RPUSH mylist "hello"
(integer) 2
redis 127.0.0.1:6379> RPUSH mylist "foo"
(integer) 3
redis 127.0.0.1:6379> RPUSH mylist "hello"
(integer) 4
redis 127.0.0.1:6379> LSET mylist 0 "bar"
OK
redis 127.0.0.1:6379> LRANGE mylist 0 -1
1: "bar"
2) "hello"
3) "foo"
4) "hello"

Redis Lists(List)

Other Extensions