Redis 列表 Lset 命令 Redis LSET 命令将列表中指定位置的元素设置为给定的值。有关索引参数的更多信息,请参见 LINDEX。对于超出范围的索引,将返回错误。 返回值 字符串响应,返回 OK。 语法 以下是 Redis LSET 命令的基本语法。 redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE BashCopy 示例 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" BashCopy