Redis LSET命令

2019-10-16 22:52:06

Redis LSET命令將在索引值的列表元素。有關索引引數的詳細資訊,請參閱LINDEX。超出索引的範圍返回一個錯誤。

返回值

返回字串:Ok

範例

redis LSET命令的基本語法如下所示:

redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE

例子

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"