Skip to main content

aerospike

The aerospike object exposes a number of methods on the database. Among them is the ability to create or update a record.

If your function can be called for both non-existing and existing records, then it is best to perform a check on the record before calling create or update:

if aerospike:exists(rec) then
aerospike:update(rec)
else
aerospike:create(rec)
end

Methods

The following are methods of aerospike.

aerospike:create()

Create a new record in the database. If create() is successful, then return 0 (zero) otherwise it is an error.

function aerospike:create(r: Record): Integer
ParameterReturns
r – the Record to create.The status code of the operation.

aerospike:update()

Update an existing record in the database. If update() is successful, then return 0 (zero) otherwise it is an error.

function aerospike:update(r: Record): Integer
ParameterReturns
r – the Record to update.The status code of the operation.

When you use a UDF to update a value in a bin, you usually follow the two-step process represented by this pseudo-code example:

record[bin] = newValue
aerospike::update(record)

However, if a bin value is a collection data type (a List or Map), an update operation by itself does not update the bin value. To ensure that a List or Map bin is recognized as modified, you must assign to the whole bin, either itself (as shown in the pseudocode below) or its modified copy.

record[bin] = newValue
record[bin] = record[bin]
aerospike::update(record)

aerospike:exists()

Checks for the existance of a record in the database. If the record exists, then true is returned, otherwise false.

function aerospike:exists(r: Record): Boolean
ParameterReturns
r – the Record to test the existence of.True if the record exists, otherwise False.

aerospike:remove()

Remove an existing record from the database. If delete() is success, then return 0 (zero), otherwise it is an error.

function aerospike:remove(r: Record): Integer
ParameterReturns
r – the Record to remove.The status code of the operation.