Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Lset Command

Redis Lset Command

Redis List

Redis Lset sets the value of an element by its index.

Returns an error when the index is out of range, or when performing LSET on an empty list.

For more information about list indices, please refer to the LINDEX 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 Version

= 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 List