Redis - List Lset Command


Advertisements

Redis LSET command sets the list element at an index to the value. For more information on the index argument, see LINDEX. An error is returned for out of range indexes.

Return Value

String reply, OK.

Syntax

Following is the basic syntax of Redis LSET command.

redis 127.0.0.1:6379> LSET KEY_NAME INDEX VALUE

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 -1 
1: "bar" 
2) "hello" 
3) "foo" 
4) "hello"
redis_lists.htm
Advertisements