LSET key index value
Set the list element at index (see LINDEX for information about the index argument) with the new value. Out-of-range indexes will generate an error.
Note that setting the first or last elements of the list is O(1).
TIME COMPLEXITY: O(N) (with N being the length of the list)
Similar to other list commands accepting indexes, the index can be negative to access elements starting from the end of the list. So -1 is the last element, -2 is the penultimate, and so forth.
RETURN VALUE: Status code reply.
Syntax:
LSET KEY_NAME INDEX VALUE
Example 1: When the key is present and the index is in the range.
redis:6379> LPUSH myList 100(integer) 1redis:6379> LSET myList 0 200"OK"
Output
OK
Example 2: When the key is not present.
redis:6379> LSET myList 0 100(error) no such key
Output
no such key
Example 3: When the index is out of range.
redis:6379> LPUSH myList 100(integer) 1redis:6379> LSET myList 1 100(error) index out of range
Output
index out of range
No comments:
Post a Comment