YouTip LogoYouTip

Lists Lset

# Redis Lset Command [!(#) Redis Lists](#) The Redis LSET command sets the value of an element in a list by its index. If the index is out of range, or if LSET is performed on an empty list, an error is returned. For more information about list indices, refer to the (#). ### Syntax The basic syntax of the Redis LSET command is as follows: redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE ### Available since >= 1.0.0 ### Return value Returns "OK" on success, otherwise returns an error message. ### Example 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 -11: "bar"2) "hello"3) "foo"4) "hello" [!(#) Redis Lists](#)")
← Lists RpushLists Lrem β†’