Skip to content

Modify operations

ListSetOp: set value at index

Updates the value at a specific index.

// Update item at index 0
_, err := client.Operate(nil, key,
as.ListSetOp("tasks", 0, "updated_task"),
)

ListRemoveOp: remove by index

Removes an item at a specific index.

// Remove first item
_, err := client.Operate(nil, key,
as.ListRemoveOp("tasks", 0),
)
// Remove last item
_, err = client.Operate(nil, key,
as.ListRemoveOp("tasks", -1),
)

ListRemoveByValueOp: remove by value

Removes all items with a specific value.

// Remove all occurrences of "completed"
_, err := client.Operate(nil, key,
as.ListRemoveByValueOp("tasks", "completed", as.ListReturnTypeCount),
)

ListPopOp: pop item

Removes and returns an item (typically used for queues).

// Pop from front (index 0)
record, err := client.Operate(nil, key,
as.ListPopOp("queue", 0),
)
item := record.Bins["queue"].(string) // Popped item

ListIncrementOp: increment numeric value

Increments a numeric value at a specific index.

// Increment counter at index 0
_, err := client.Operate(nil, key,
as.ListIncrementOp("counters", 0, 1),
)

ListClearOp: clear all items

Removes all items from the list.

// Clear entire list
_, err := client.Operate(nil, key,
as.ListClearOp("tasks"),
)
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?