Redis - LSET 命令



Redis LSET 命令將列表元素在索引處設定為此值。有關索引引數的更多資訊,請參見 LINDEX。對於超出範圍的索引,將返回錯誤。

返回值

字串響應,確定。

語法

以下是 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"
redis_lists.htm
廣告