Skip to content

Best practices and tips

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

These best practices help you use Collection Data Type (CDT) operations in the Aerospike Go client efficiently and read their results correctly. They cover performance choices, such as server-side operations and batching, and the type assertions that CDT results need.

Performance considerations

  1. Use server-side operations: Prefer CDT operations over read-modify-write patterns.
  2. Batch operations: Combine multiple operations in a single Operate() call.
  3. Choose appropriate policies: Use UNORDERED when order doesn’t matter for better performance.
  4. Limit nested depth: Deep nesting can impact performance.

Type assertions for results

Results from CDT operations may need type assertions:

results := record.Bins["profile"].(as.OpResults)
// String values
name := results[0].(string)
// Integer values (server returns as int)
age := results[0].(int)
// Float values
price := results[0].(float64)
// Boolean values
active := results[0].(bool)
// Map values
profile := results[0].(map[any]any)
// List values
items := results[0].([]any)
// MapPair for KEY_VALUE return type
pair := results[0].(as.MapPair)

Next steps