LSET

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Replace the value at a given index

Usage is lset key index value.
Replaces the value at the given index with a new value.
From the left, indexes are 0, 1, 2; from the right they are -1, -2, -3.

Example

Command>lpush mylist value1 value2 value3 value4
Result>4
Command>lrange mylist 0 -1
Result>0) value4
1) value3
2) value2
3) value1
Command>lset mylist 0 "XXXXX"
Result>OK
Command>lset mylist 2 "YYYYY"
Result>OK
Command>lset mylist -1 "ZZZZZ"
Result>OK
Command>lrange mylist 0 -1
Result>0) XXXXX
1) value3
2) YYYYY
3) ZZZZZ

View animation



Syntax

LSET key index value

  • Available since version 1.0.0.
  • Time complexity is O(N). N is the number of elements.
    Setting the first or last element of the list is O(1).
Related commands LINDEX, LINSERT, LREM
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< LPOS LSET LINSERT >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.