无涯教程-Redis - LSET命令函数

89 阅读1分钟

Redis LSET 命令将列表元素的索引值设置为该值,有关index参数的更多信息,请参见LINDEX,超出范围的索引将返回错误。

LSET - 返回值

返回OK字符串。

LSET - 语法

以下是Redis LSET 命令的基本语法。

redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE

LSET - 示例

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"

参考链接

www.learnfk.com/redis/lists…