Latest web development tutorials

Redis Lset command

Redis list (List)

Redis Lset to set the value of the element by index.

When the index parameter is out of range, or an empty list LSET, it returns an error.

For more information on the subject under the list, refer to LINDEX command .

grammar

redis Lset basic command syntax is as follows:

redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE

Available versions

> = 1.0.0

return value

Operation successful return ok, otherwise it returns an error message.

Examples

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 (List)