Skip to content

Get operations

ListGetOp: get by index

Retrieves a value by its index position. Supports negative indexing (-1 = last item).

// Get first item (index 0)
record, err := client.Operate(nil, key,
as.ListGetOp("tasks", 0),
)
firstTask := record.Bins["tasks"].(string)
fmt.Println("firstTask: ", firstTask)
// Get last item (index -1)
record, err = client.Operate(nil, key,
as.ListGetOp("tasks", -1),
)

ListGetRangeOp: get range of items

Retrieves a range of items from the list.

// Get first 10 items (from index 0, count 10)
record, err := client.Operate(nil, key,
as.ListGetRangeOp("tasks", 0, 10),
)
results := record.Bins["tasks"].([]any)
firstTask := results[0].(string)

ListGetByIndexOp: get by index with return type

Similar to ListGetOp but with explicit return type control.

// Get index of a value
record, err := client.Operate(nil, key,
as.ListGetByIndexOp("items", 1, as.ListReturnTypeIndex)
)

ListGetByRankOp: get by rank

Retrieves an item by its rank (sorted by value).

// Get item with lowest value (rank 0)
record, err := client.Operate(nil, key,
as.ListGetByRankOp("scores", 0, as.ListReturnTypeValue),
)

ListGetByValueOp: Get by Value

Finds the index of items with a specific value.

// Find index of value "target"
record, err := client.Operate(nil, key,
as.ListGetByValueOp("items", "target", as.ListReturnTypeIndex),
)
indices := record.Bins["items"].([]any) // All indices where value appears

ListSizeOp: get list size

Returns the number of items in the list.

// Get list size
record, err := client.Operate(nil, key,
as.ListSizeOp("tasks"),
)
size := record.Bins["queue"].(int)
fmt.Printf("Queue has %d tasks\n", size)
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?