lset.3valkey - Man Page

Sets the value of an element in a list by its index.

Synopsis

LSET key index element

Description

Sets the list element at index to element. For more information on the index argument, see valkey-lindex(7) LINDEX.

An error is returned for out of range indexes.

Reply

valkey-protocol(7) Simple string reply: OK.

Complexity

O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1).

Acl Categories

@list @slow @write

History

Examples

127.0.0.1:6379> RPUSH mylist "one"
(integer) 1
127.0.0.1:6379> RPUSH mylist "two"
(integer) 2
127.0.0.1:6379> RPUSH mylist "three"
(integer) 3
127.0.0.1:6379> LSET mylist 0 "four"
OK
127.0.0.1:6379> LSET mylist -2 "five"
OK
127.0.0.1:6379> LRANGE mylist 0 -1
1) "four"
2) "five"
3) "three"

See Also

blmove(3valkey), blmpop(3valkey), blpop(3valkey), brpop(3valkey), brpoplpush(3valkey), lindex(3valkey), linsert(3valkey), llen(3valkey), lmove(3valkey), lmpop(3valkey), lpop(3valkey), lpos(3valkey), lpush(3valkey), lpushx(3valkey), lrange(3valkey), lrem(3valkey), ltrim(3valkey), rpop(3valkey), rpoplpush(3valkey), rpush(3valkey), rpushx(3valkey)

Info

2025-10-21 9.0.0 Valkey Command Manual