Record Operations
Aerospike provides simple interfaces for reading data from and writing data to an Aerospike cluster. They cover the standard CRUD (create, read, update, delete) use-cases.
Every Aerospike client can perform the following full-record operations, no matter which language it's written in:
Operation | Description |
---|---|
put | Write a record. Performs the equivalent of create , update or replace , depending on the write policy given to the put operation. |
delete | Remove a record from the database. Generates a tombstone when using the durable-delete policy. |
get | Read the record. Specific bins can be selected. |
add | Add (or subtract) a value in an integer bin. Used to implement counters. Also called increment . |
append prepend | Modify a string or byte array bin. |
touch | Increment the generation counter. |
operate | Apply multiple bin operations as an atomic transaction. |
Best practice is to apply add
and append
/prepend
operations as part of a transaction, and not to use the full-record operation variant described above.
Filtering Operationsโ
An operation can be conditionally applied, based on the result of a filter expression. If the filter expression evaluates to true, the operation will execute. Older versions starting with Aerospike 4.7 can apply a predicate filter to the operation.
Support for predicate filters is removed in Aerospike 6.0, so we recommend that filter expressions added in version 5.2 be used in their place.
Code examples of record operationsโ
The following examples use Python to perform create, read, update, and delete (CRUD) operations on a record. The syntax differs per Aerospike client, based on the needs of the operating system. These examples model common usage:
Create a recordโ
key = (namespace_name, set_name, user_key)
bins = {
'l': [ "qwertyuiop", 1, bytearray("asd;as[d'as;d", "utf-8") ],
'm': { "key": "asd';q;'1';" },
'i': 1234,
'f': 3.14159265359,
's': '!@#@#$QSDAsd;as'
}
client.put(key, bins)
Arguments:
key
: The primary key of the record to create.bins
: Bin name and value pairs to insert into the bins upon creation.
Read a recordโ
client.get(key)
Arguments:
key
: The primary key of the record to read.
Update a recordโ
update_bins = {
'b'=: u"\ud83d\ude04"
'i': aerospike.null()
}
client.put(key, update_bins)
Arguments:
key
: The primary key of the record to update.update_bins
: Bin name and value pairs to upsert into the bins.
Adds a blob bin. Removes the integer bin by overwriting with null.
Delete a recordโ
client.remove(key)
Arguments:
key
: The primary key of the record to delete.
Usage note for all examplesโ
All full-record read and write operations accept policy parameters: Max Retries and Total Timeout.
Write operations take an optional time-to-live (TTL) parameter that specifies how long to protect a record from automatic eviction by the system. Set the TTL to -1 to tell Aerospike to never evict that data.
Referencesโ
See these topics for language-specific examples: