This notebook requires Aerospike database running on localhost and that python and the
Aerospike python client have been installed (pip install aerospike).
Visit Aerospike notebooks
repo for
additional details and the docker container.
The configuration is for Aerospike database running on port 3000 of
localhost (IP 127.0.0.1) which is the default. Modify config if your
environment is different (Aerospike database running on a different host
or different port).
config = {
'hosts': [ ('127.0.0.1', 3000) ]
}
print("Configuring with seed host:", config['hosts'])
The three components namespace, set, and userkey (with set being
optional) form the Primary Key (PK) or simply key, of the record. The
key serves as a handle to the record, and using it, a record can be read
or written. For a detailed description of the data model see the Data
Model
overview
Aerospike is schema-less and records may be written without any other
setup. Here the bins or fields: name, age and greeting, are being
written to a record with the key as defined above.
Print the record that was just retrieved. We are also printing:
The components of the key which are: namespace, set, and userkey. By
default userkey is not stored on server, only a hash (appearing as
bytearray in the output below) which is the internal representation
of the key is stored.
The metadata with the time-to-live and the record’s generation or
version.
The actual value of the record’s bins.
print("Record contents are", record)
print("Key's components are", key)
print("Metadata is", metadata)
Output
Record contents are {'name': 'John Doe', 'age': 32, 'gpa': 4.3, 'greeting': 'Hello, World!'}
Key's components are ('test', 'demo', None, bytearray(b'\xf5~\xc1\x835\xf7\x10\x0c\x04X\xf8\xa6D\xbc\xbcvm\x93G\x1e'))
Visit Aerospike notebooks
repo to
run additional Aerospike notebooks. To run a different notebook,
download the notebook from the repo to your local machine, and then
click on File > Open, and select Upload.