Command: LIST.SET
Overview
The LIST.SET
command clears the existing elements associated with a given list key and sets the provided values as the new list elements. It effectively replaces any previously stored data under the key with the new list.
Command Name
LIST.SET
Description
Replaces all elements in a list with new ones provided during the call. This command clears existing contents at the specified key and sets the new list items from the input. Returns the number of elements added to the list (as an index count).
Use Cases
-
Replace existing list data: Ideal when a complete list reset is required for a given key.
-
Atomic overwrite of list: Ensures old list values are cleared and new ones are inserted in a single operation.
-
Staging or configuration reset: Useful for overwriting cached configurations, logs, or batch records.
Syntax
LIST.SET <key> [<value>...]
-
<key>
: The name of the list where the data will be set. -
<value>
: One or more elements to be inserted into the list.
Note: If the key is invalid or the argument list is insufficient, an error is returned.
Permissions
Requires write access to the given key.
Examples
Example 1 – Single element
localhost:9219> LIST.SET myList "First element"
Ok 1
Example 2 – Multiple elements
localhost:9219> LIST.SET myList "First" "Second" "Third"
Ok 3
Retrieve elements
localhost:9219> LIST.GET myList
Ok [
"First",
"Second",
"Third"
]
Behavior on Error
Scenario | Error Message |
---|---|
No key provided | INVALID_KEY: Key must be provided |
Less than 2 arguments (missing value) | INVALID_ARGS: invalid number of arguments, Syntax: LIST.SET <key> [<value>] |
Invalid key format | INVALID_KEY: <error description> |
Internal store error | <error returned by the shard or WAL> |