Easy Tutorial
❮ Redis Geo Server Config Resetstat ❯

Redis Lset Command

Redis Lists

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

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

For more information on list indices, 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 Versions

= 1.0.0

Return Value

Returns "OK" if the operation is successful, 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

❮ Redis Geo Server Config Resetstat ❯