Skip to main content

Read a Record

Jump to the Code block for a combined complete example.

Setup

The following examples will use the setup and record below to illustrate single record data retreival from an Aerospike database.

The record structure:

+------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+
| PK | occurred | reported | posted | report | location |
+------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+
| 5001 | 20220531 | 20220601 | 20220601 | MAP('{"shape":["circle", "flash", "disc"], "summary":"Large flying disc flashed in the sky above the student union. Craziest thing I've ever seen!", "city":"Ann Arbor", "state":"Michigan", "duration":"5 minutes"}') | GeoJSON('{"type":"Point","coordinates":[42.2808,83.743]}') |
+------+----------+----------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------+

Policies

Instead of using the default read policies, we can set them on a per transaction basis.

The following example creates a new read policy and sets the socket timeout for the transaction.

Read a record

Record exists

Checking record existence is faster than getting the record because it only needs to look at the primary index.

Record metadata only

Read record metadata (generation and expiration information) without reading the bins for a specified key.

Whole record

Read the record metadata and all bins for a specified key.

Specific bins

Read the record metadata and the report and location bins from the record.

Code block

Expand this section for a single code block to read a record