![]() |
Records in Aerospike are collections of named bins.
The bins in a record are analogous to columns in relational databases. However, unlike columns, the bins themselves are not typed. Instead, bins contain values which are typed. So, it is possible to have multiple records with bins of the same name but different types for values.
The bin's value can only be of the types defined in as_bin_value
.
There are several ways to initialize an as_record
.
You can create the as_record
on the stack:
Then initialize it using either the as_record_init()
function or as_record_inita()
macro.
The as_record_init()
function will initialize the variable, then allocate the specified number of bins using malloc()
. The following initializes rec
with 2 bins.
The as_record_inita()
macro will initialize the variable, then allocate the specified number of bins using alloca()
. The following initializes rec
with 2 bins.
The as_record_new()
function will allocate an as_record
on the heap using malloc()
then allocate the specified number of bins using malloc()
. The following creates a new as_record
with 2 bins.
When you no longer require an as_record, you should call as_record_destroy()
to release the record and associated resources.
If the record has been ref-counted, then the ref-count will be decremented, until it reaches 0 (zero), at which point, the record will be released.
The following are functions for setting values in bins of a record. Utilize the appropriate setter for the data you want to store in a bin.
Function | Description |
---|---|
as_record_set_int64() | Set the bin value to a 64-bit integer. |
as_record_set_str() | Set the bin value to a NULL-terminated string. |
as_record_set_integer() | Set the bin value to an as_integer . |
as_record_set_string() | Set the bin value to an as_string . |
as_record_set_bytes() | Set the bin value to an as_bytes . |
as_record_set_list() | Set the bin value to an as_list . |
as_record_set_map() | Set the bin value to an as_map . |
as_record_set_nil() | Set the bin value to an as_nil . |
as_record_set() | Set the bin value to an as_bin_value . |
The following are functions for getting values from bins of a record. Utilize the appropriate getter for the data you want to read from a bin.
Function | Description |
---|---|
as_record_get_int64() | Get the bin as a 64-bit integer. |
as_record_get_str() | Get the bin as a NULL-terminated string. |
as_record_get_integer() | Get the bin as an as_integer . |
as_record_get_string() | Get the bin as an as_string . |
as_record_get_bytes() | Get the bin as an as_bytes . |
as_record_get_list() | Get the bin as an as_list . |
as_record_get_map() | Get the bin as an as_map . |
as_record_get() | Get the bin as an as_bin_value . |
If you are unsure of the type of data stored in the bin, then you should use as_record_get()
. You can then check the type of the value using as_val_type()
.
If you want to traverse the bins of a record, then you have two options:
Definition at line 158 of file as_record.h.
#include "as_record.h"
Data Fields | |
as_bins | bins |
uint16_t | gen |
as_key | key |
uint32_t | ttl |
![]() | |
void * | data |
struct as_rec_hooks_s * | hooks |
![]() | |
cf_atomic32 | count |
bool | free |
enum as_val_t | type |
Private Attributes | |
as_rec | _ |
Related Functions | |
(Note that these are not member functions.) | |
void | as_record_destroy (as_record *rec) |
bool | as_record_foreach (const as_record *rec, as_rec_foreach_callback callback, void *udata) |
static as_record * | as_record_fromval (const as_val *v) |
as_bin_value * | as_record_get (const as_record *rec, const as_bin_name name) |
as_bytes * | as_record_get_bytes (const as_record *rec, const as_bin_name name) |
int64_t | as_record_get_int64 (const as_record *rec, const as_bin_name name, int64_t fallback) |
as_integer * | as_record_get_integer (const as_record *rec, const as_bin_name name) |
as_list * | as_record_get_list (const as_record *rec, const as_bin_name name) |
as_map * | as_record_get_map (const as_record *rec, const as_bin_name name) |
char * | as_record_get_str (const as_record *rec, const as_bin_name name) |
as_string * | as_record_get_string (const as_record *rec, const as_bin_name name) |
as_record * | as_record_init (as_record *rec, uint16_t nbins) |
#define | as_record_inita(__rec, __nbins) |
as_record * | as_record_new (uint16_t nbins) |
uint16_t | as_record_numbins (const as_record *rec) |
bool | as_record_set (as_record *rec, const as_bin_name name, as_bin_value *value) |
bool | as_record_set_bytes (as_record *rec, const as_bin_name name, as_bytes *value) |
bool | as_record_set_int64 (as_record *rec, const as_bin_name name, int64_t value) |
bool | as_record_set_integer (as_record *rec, const as_bin_name name, as_integer *value) |
bool | as_record_set_list (as_record *rec, const as_bin_name name, as_list *value) |
bool | as_record_set_map (as_record *rec, const as_bin_name name, as_map *value) |
bool | as_record_set_nil (as_record *rec, const as_bin_name name) |
static bool | as_record_set_raw (as_record *rec, const as_bin_name name, const uint8_t *value, uint32_t size) |
bool | as_record_set_raw_typep (as_record *rec, const as_bin_name name, const uint8_t *value, uint32_t size, as_bytes_type type, bool free) |
bool | as_record_set_rawp (as_record *rec, const as_bin_name name, const uint8_t *value, uint32_t size, bool free) |
static bool | as_record_set_str (as_record *rec, const as_bin_name name, const char *value) |
bool | as_record_set_string (as_record *rec, const as_bin_name name, as_string *value) |
bool | as_record_set_strp (as_record *rec, const as_bin_name name, const char *value, bool free) |
static as_val * | as_record_toval (const as_record *rec) |
![]() | |
static int | as_rec_bin_names (const as_rec *rec, as_rec_bin_names_callback callback, void *udata) |
as_rec * | as_rec_cons (as_rec *rec, bool free, void *data, const as_rec_hooks *hooks) |
static void | as_rec_destroy (as_rec *rec) |
static as_bytes * | as_rec_digest (const as_rec *rec) |
static int | as_rec_drop_key (const as_rec *rec) |
static bool | as_rec_foreach (const as_rec *rec, as_rec_foreach_callback callback, void *udata) |
static as_rec * | as_rec_fromval (const as_val *v) |
static uint16_t | as_rec_gen (const as_rec *rec) |
static as_val * | as_rec_get (const as_rec *rec, const char *name) |
static as_bytes * | as_rec_get_bytes (const as_rec *rec, const char *name) |
static int64_t | as_rec_get_int64 (const as_rec *rec, const char *name) |
static as_integer * | as_rec_get_integer (const as_rec *rec, const char *name) |
static as_list * | as_rec_get_list (const as_rec *rec, const char *name) |
static as_map * | as_rec_get_map (const as_rec *rec, const char *name) |
static char * | as_rec_get_str (const as_rec *rec, const char *name) |
static as_string * | as_rec_get_string (const as_rec *rec, const char *name) |
as_rec * | as_rec_init (as_rec *rec, void *data, const as_rec_hooks *hooks) |
static as_val * | as_rec_key (const as_rec *rec) |
as_rec * | as_rec_new (void *data, const as_rec_hooks *hooks) |
static uint16_t | as_rec_numbins (const as_rec *rec) |
static int | as_rec_remove (const as_rec *rec, const char *name) |
static int | as_rec_set (const as_rec *rec, const char *name, const as_val *value) |
static int | as_rec_set_bytes (const as_rec *rec, const char *name, const as_bytes *value) |
static int | as_rec_set_flags (const as_rec *rec, const char *name, uint8_t flags) |
static int | as_rec_set_int64 (const as_rec *rec, const char *name, int64_t value) |
static int | as_rec_set_integer (const as_rec *rec, const char *name, const as_integer *value) |
static int | as_rec_set_list (const as_rec *rec, const char *name, const as_list *value) |
static int | as_rec_set_map (const as_rec *rec, const char *name, const as_map *value) |
static int | as_rec_set_str (const as_rec *rec, const char *name, const char *value) |
static int | as_rec_set_string (const as_rec *rec, const char *name, const as_string *value) |
static int | as_rec_set_ttl (const as_rec *rec, uint32_t ttl) |
static int | as_rec_set_type (const as_rec *rec, int8_t rec_type) |
static const char * | as_rec_setname (const as_rec *rec) |
static void * | as_rec_source (const as_rec *rec) |
static as_val * | as_rec_toval (const as_rec *rec) |
static uint32_t | as_rec_ttl (const as_rec *rec) |
|
related |
Destroy the as_record and associated resources.
rec | The record to destroy. |
|
related |
Iterate over each bin in the record and invoke the callback function.
If the callback returns true, then iteration will continue to the next bin. Otherwise, the iteration will halt and as_record_foreach()
will return false.
rec | The record containing the bins to iterate over. |
callback | The callback to invoke for each bin. |
udata | User-data provided for the callback. |
Convert from an as_val.
Definition at line 739 of file as_record.h.
References AS_REC, and as_util_fromval.
|
related |
Get specified bin's value.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Get specified bin's value as an as_bytes.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Get specified bin's value as an int64_t.
rec | The record containing the bin. |
name | The name of the bin. |
fallback | The default value to use, if the bin doesn't exist or is not an integer. |
|
related |
Get specified bin's value as an as_integer.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Get specified bin's value as an as_list.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Get specified bin's value as an as_map.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Get specified bin's value as an NULL terminated string.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Get specified bin's value as an as_string.
rec | The record containing the bin. |
name | The name of the bin. |
Initializes an as_record created on the stack.
When you are finished using the as_record
instance, you should release the resources allocated to it by calling as_record_destroy()
.
rec | The record to initialize. |
nbins | The number of bins to initialize. Set to 0, if unknown. |
|
related |
Initialize a stack allocated as_record
then allocate __nbins
capacity for as_record.bins on the stack.
When you are finished using the as_record
instance, you should release the resources allocated to it by calling as_record_destroy()
.
__rec | The as_record * to initialize. |
__nbins | The number of as_record.bins.entries to allocate on the stack. |
Definition at line 236 of file as_record.h.
|
related |
Create a new as_record on the heap.
When you are finished using the as_record
instance, you should release the resources allocated to it by calling as_record_destroy()
.
nbins | The number of bins to initialize. Set to 0, if unknown. |
|
related |
Get the number of bins in the record.
|
related |
Set specified bin's value to an as_bin_value.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to an as_bytes.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to an int64_t.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to an as_integer.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to an as_list.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to an as_map.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to as_nil.
rec | The record containing the bin. |
name | The name of the bin. |
|
related |
Set specified bin's value to an NULL terminated string.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
size | The size of the value. Must last for the lifetime of the record. |
Definition at line 441 of file as_record.h.
References as_record_set_rawp().
|
related |
Set specified bin's value to an as_bytes value of a specified type.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
size | The size of the value. |
type | The as_bytes_type designation (AS_BYTES_*) |
free | If true, then the value will be freed when the record is destroyed. |
|
related |
Set specified bin's value to an NULL terminated string.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
size | The size of the value. |
free | If true, then the value will be freed when the record is destroyed. |
|
related |
Set specified bin's value to an NULL terminated string.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. Must last for the lifetime of the record. |
Definition at line 370 of file as_record.h.
References as_record_set_strp().
|
related |
Set specified bin's value to an as_string.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
|
related |
Set specified bin's value to an NULL terminated string.
rec | The record containing the bin. |
name | The name of the bin. |
value | The value of the bin. |
free | If true, then the value will be freed when the record is destroyed. |
Convert to an as_val.
Definition at line 729 of file as_record.h.
|
private |
as_bins as_record::bins |
The bins of the record.
Definition at line 195 of file as_record.h.
uint16_t as_record::gen |
The generation of the record.
Definition at line 177 of file as_record.h.
as_key as_record::key |
The key of the record. This is populated when a record is read from the database. This should not be set by the user.
Definition at line 172 of file as_record.h.
uint32_t as_record::ttl |
The time-to-live (expiration) of the record in seconds. There are two special values that can be set in the record TTL: (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the record will adopt the default TTL value from the namespace. (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int) (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record will get an internal "void_time" of zero, and thus will never expire.
Note that the TTL value will be employed ONLY on write/update calls.
Definition at line 190 of file as_record.h.