Supported data types
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
The Aerospike C client supports these data types for bin values:
- Blob
- Boolean
- Double
- GeoJSON
- HyperLogLog
- Integer
- List
- Map
- String
Each type has a C value type. as_record has functions to set and get a bin of each type, except HyperLogLog, which you write with HLL operations:
| Data type | C value type | Write with | Read with |
|---|---|---|---|
| Blob | as_bytes | as_record_set_raw(), as_record_set_bytes() | as_record_get_bytes() |
| Boolean | as_boolean | as_record_set_bool() | as_record_get_bool() |
| Double | as_double | as_record_set_double() | as_record_get_double() |
| GeoJSON | as_geojson | as_record_set_geojson_str() | as_record_get_geojson_str() |
| HyperLogLog | as_bytes of type AS_BYTES_HLL | HLL operations, such as as_operations_hll_add() | as_record_get_bytes() |
| Integer | as_integer | as_record_set_int64() | as_record_get_int64() |
| List | as_list, such as as_arraylist | as_record_set_list() | as_record_get_list() |
| Map | as_map, such as as_hashmap | as_record_set_map() | as_record_get_map() |
| String | as_string | as_record_set_str() | as_record_get_str() |
An integer is a signed 64-bit int64_t. The client stores the bytes of a string as they are, without converting them, so store strings as UTF-8 for clients in other languages to read them. A blob is stored as raw bytes, which every client reads as a byte array.
Setting a bin to as_nil with as_record_set_nil() in a write removes that bin from the record.
Keys can be integers, strings, or byte arrays. Initialize them with as_key_init_int64(), as_key_init_str(), or as_key_init_raw().
For other data types, including compound objects, use a List or Map, or serialize the value with a format such as Protobuf, MessagePack, or JSON and store the result in a blob.
Example
The following example writes a record with one bin of each type except HyperLogLog, then reads it back. It assumes an established cluster connection in as.
as_error err;as_key key;as_key_init_str(&key, "test", "demo", "types");
as_arraylist list;as_arraylist_init(&list, 3, 0);as_arraylist_append_int64(&list, 1);as_arraylist_append_str(&list, "two");as_arraylist_append_double(&list, 3.5);
as_hashmap map;as_hashmap_init(&map, 2);as_stringmap_set_int64((as_map*)&map, "count", 7);as_stringmap_set_str((as_map*)&map, "color", "blue");
uint8_t blob[] = { 0x01, 0x02, 0x03 };
as_record rec;as_record_inita(&rec, 8);as_record_set_int64(&rec, "int", 123);as_record_set_double(&rec, "double", 9.99);as_record_set_str(&rec, "string", "hello");as_record_set_bool(&rec, "bool", true);as_record_set_raw(&rec, "blob", blob, sizeof(blob));as_record_set_geojson_str(&rec, "geo", "{\"type\":\"Point\",\"coordinates\":[-122.0,37.5]}");as_record_set_list(&rec, "list", (as_list*)&list);as_record_set_map(&rec, "map", (as_map*)&map);
if (aerospike_key_put(&as, &err, NULL, &key, &rec) != AEROSPIKE_OK) { fprintf(stderr, "err(%d) %s\n", err.code, err.message);}as_record_destroy(&rec);
as_record* out = NULL;if (aerospike_key_get(&as, &err, NULL, &key, &out) == AEROSPIKE_OK) { char* list_str = as_val_tostring(as_record_get_list(out, "list"));
printf("int: %" PRId64 "\n", as_record_get_int64(out, "int", 0)); printf("double: %.2f\n", as_record_get_double(out, "double", 0.0)); printf("string: %s\n", as_record_get_str(out, "string")); printf("bool: %s\n", as_record_get_bool(out, "bool") ? "true" : "false"); printf("blob: %u bytes\n", as_bytes_size(as_record_get_bytes(out, "blob"))); printf("geo: %s\n", as_record_get_geojson_str(out, "geo")); printf("list: %s\n", list_str); printf("map: color=%s\n", as_stringmap_get_str(as_record_get_map(out, "map"), "color"));
free(list_str); as_record_destroy(out);}else { fprintf(stderr, "err(%d) %s\n", err.code, err.message);}The example prints:
int: 123double: 9.99string: hellobool: trueblob: 3 bytesgeo: {"type":"Point","coordinates":[-122.0,37.5]}list: [1, "two", 3.5]map: color=blue