Skip to content

List Commands

List commands operate on Redis lists — ordered collections of strings. Lists are doubly-linked, so adding elements to the head or tail is very fast.

This page covers: BLMOVE, BLPOP, BRPOP, LMOVE, LPOP, LPUSH, LSET, RPOP, RPUSH


LPUSH

Prepend one or more values to a list.

📘 Redis Reference: LPUSH

XML Example

xml
<lettuce-redis:lpush doc:name="Push to queue"
    config-ref="Redis_Config"
    key="queue:tasks"
    members="#[['task-1', 'task-2', 'task-3']]"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe list key
membersList<String>YesValues to prepend. At least one required. Payload by default via @Content.

Output

Type: Long

The length of the list after the operation.

Errors

Error TypeCondition
REDIS:ARGUMENTNo members provided
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a list

RPUSH

Append one or more values to a list.

📘 Redis Reference: RPUSH

XML Example

xml
<lettuce-redis:rpush doc:name="Append to log"
    config-ref="Redis_Config"
    key="log:events"
    members="#[['event-1', 'event-2']]"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe list key
membersList<String>YesValues to append. At least one required. Payload by default via @Content.

Output

Type: Long

The length of the list after the operation.

Errors

Error TypeCondition
REDIS:ARGUMENTNo members provided
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a list

LPOP

Remove and return the first element(s) from a list.

📘 Redis Reference: LPOP

XML Example

xml
<!-- Pop a single element -->
<lettuce-redis:lpop doc:name="Pop one"
    config-ref="Redis_Config"
    key="queue:tasks"/>
<!-- payload is a List<String> with one element -->

<!-- Pop multiple elements -->
<lettuce-redis:lpop doc:name="Pop three"
    config-ref="Redis_Config"
    key="queue:tasks"
    count="3"/>
<!-- payload is a List<String> with up to three elements -->

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe list key
countIntegerNoNumber of elements to pop. When omitted, pops one element.

Output

Type: List<String>

The operation always returns a List<String> regardless of whether count is provided:

  • When count is not specified: list contains a single element (the popped element)
  • When count is specified: list contains up to count popped elements

Metadata Mismatch

Anypoint Studio's design-time metadata indicates this operation returns a String when count is not provided. At runtime, the operation always returns a List<String>. When writing DataWeave expressions, treat the output as a list. This mismatch is tracked in issue #4.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a list

RPOP

Remove and return the last element(s) from a list.

📘 Redis Reference: RPOP

XML Example

xml
<!-- Pop a single element -->
<lettuce-redis:rpop doc:name="Pop last"
    config-ref="Redis_Config"
    key="stack:items"/>
<!-- payload is a List<String> with one element -->

<!-- Pop multiple elements -->
<lettuce-redis:rpop doc:name="Pop last three"
    config-ref="Redis_Config"
    key="stack:items"
    count="3"/>
<!-- payload is a List<String> with up to three elements -->

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe list key
countIntegerNoNumber of elements to pop

Output

Type: List<String>

The operation always returns a List<String> regardless of whether count is provided:

  • When count is not specified: list contains a single element (the popped element)
  • When count is specified: list contains up to count popped elements

Metadata Mismatch

Anypoint Studio's design-time metadata indicates this operation returns a String when count is not provided. At runtime, the operation always returns a List<String>. When writing DataWeave expressions, treat the output as a list. This mismatch is tracked in issue #4.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a list

BLPOP

Remove and return the first element from one of multiple lists, blocking until an element is available or timeout occurs.

📘 Redis Reference: BLPOP

XML Example

xml
<!-- Block for up to 5 seconds waiting for a task -->
<lettuce-redis:blpop doc:name="Wait for task"
    config-ref="Redis_Config"
    keys="#[['queue:high-priority', 'queue:normal', 'queue:low']]"
    timeoutSeconds="5"/>

<!-- payload is a Map<String, String> with one entry: the key and the popped value -->
<logger level="INFO"
    message="Popped from #[payload.keys()[0]]: #[payload[payload.keys()[0]]]"/>

Parameters

ParameterTypeRequiredDefaultDescription
keysList<String>YesOne or more list keys to wait on. At least one required. The first list to have an element available is popped.
timeoutSecondsDoubleYesSeconds to wait. Use 0 to block indefinitely.

Output

Type: Map<String, String>

A single-entry map where:

  • Key: The list key that had an element
  • Value: The popped element

Errors

Error TypeCondition
REDIS:ARGUMENTNo keys provided
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEOne of the keys is not a list
REDIS:TIMEOUTTimeout reached with no element available

BRPOP

Remove and return the last element from one of multiple lists, blocking until an element is available or timeout occurs.

📘 Redis Reference: BRPOP

XML Example

xml
<lettuce-redis:brpop doc:name="Wait for message"
    config-ref="Redis_Config"
    keys="#[['messages:inbox']]"
    timeoutSeconds="10"/>

Parameters

ParameterTypeRequiredDefaultDescription
keysList<String>YesOne or more list keys. At least one required.
timeoutSecondsDoubleYesSeconds to wait. Use 0 to block indefinitely.

Output

Type: Map<String, String>

A single-entry map: the key that had an element and the popped value.

Errors

Error TypeCondition
REDIS:ARGUMENTNo keys provided
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEOne of the keys is not a list
REDIS:TIMEOUTTimeout reached with no element available

LMOVE

Atomically move an element from one list to another.

📘 Redis Reference: LMOVE

XML Example

xml
<!-- Move task from pending to in-progress queue -->
<lettuce-redis:lmove doc:name="Move task to processing"
    config-ref="Redis_Config"
    source="queue:pending"
    destination="queue:in-progress"
    whereFrom="LEFT"
    whereTo="RIGHT"/>

<!-- payload now contains the moved element -->

Parameters

ParameterTypeRequiredDefaultDescription
sourceStringYesSource list key
destinationStringYesDestination list key
whereFromListEndYesWhich end to pop from the source list: LEFT or RIGHT
whereToListEndYesWhich end to push to the destination list: LEFT or RIGHT

ListEnd values: LEFT, RIGHT

Output

Type: String (media type: text/plain)

The element that was moved.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPESource or destination is not a list

Queue Transfer Pattern

xml
<!-- Implement a reliable queue: move tasks from "pending" to "in-progress" -->
<flow name="process-tasks">
    <scheduler>
        <scheduling-strategy>
            <fixed-frequency frequency="1" timeUnit="SECONDS"/>
        </scheduling-strategy>
    </scheduler>

    <try>
        <lettuce-redis:lmove
            config-ref="Redis_Config"
            source="queue:pending"
            destination="queue:in-progress"
            whereFrom="LEFT"
            whereTo="RIGHT"/>

        <!-- Process the task -->
        <flow-ref name="process-task"/>

        <!-- On success, remove from in-progress -->
        <lettuce-redis:rpop
            config-ref="Redis_Config"
            key="queue:in-progress"/>

        <error-handler>
            <on-error-continue>
                <!-- On failure, move back to pending -->
                <lettuce-redis:lmove
                    config-ref="Redis_Config"
                    source="queue:in-progress"
                    destination="queue:pending"
                    whereFrom="RIGHT"
                    whereTo="LEFT"/>
            </on-error-continue>
        </error-handler>
    </try>
</flow>

BLMOVE

Atomically move an element from one list to another, blocking until an element is available or timeout occurs.

📘 Redis Reference: BLMOVE

XML Example

xml
<lettuce-redis:blmove doc:name="Wait and move task"
    config-ref="Redis_Config"
    source="queue:pending"
    destination="queue:in-progress"
    whereFrom="LEFT"
    whereTo="RIGHT"
    timeout="5.0"/>

Parameters

ParameterTypeRequiredDefaultDescription
sourceStringYesSource list key
destinationStringYesDestination list key
whereFromListEndYesWhich end to pop from: LEFT or RIGHT
whereToListEndYesWhich end to push to: LEFT or RIGHT
timeoutDoubleYesSeconds to wait for an element. Use 0.0 to block indefinitely.

Output

Type: String (media type: text/plain)

The element that was moved.

Errors

Error TypeCondition
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPESource or destination is not a list

LSET

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

📘 Redis Reference: LSET

XML Example

xml
<!-- Update the first element (index 0) -->
<lettuce-redis:lset doc:name="Update first item"
    config-ref="Redis_Config"
    key="todo:items"
    index="0"
    element="Buy groceries (URGENT)"/>

<!-- Update the last element (index -1) -->
<lettuce-redis:lset doc:name="Update last item"
    config-ref="Redis_Config"
    key="todo:items"
    index="-1"
    element="Call mom"/>

Parameters

ParameterTypeRequiredDefaultDescription
keyStringYesThe list key
indexLongYesIndex of the element to set (0-based). Negative indices count from the end (-1 is last element).
elementStringYesThe new value (payload by default via @Content)

Output

Type: Void

Errors

Error TypeCondition
REDIS:OUT_OF_RANGEIndex is out of range for the list
REDIS:COMMANDGeneral command execution error
REDIS:WRONG_TYPEKey exists but is not a list

Released under the MIT License.