Delete
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
Use aerospike_key_remove() to delete data from the database.
These examples are in examples/basic_examples/put in the Aerospike C client package.
The client must have an established the cluster connection.
Initializing the Key
The application identifies records in the database using a key. In this example, the value for key is the string test-key, to delete from namespace test within the set test-set.
as_key key;as_key_init_str(&key, "test", "test-set", "test-key");Deleting Records
To delete the record from the database:
if (aerospike_key_remove(&as, &err, NULL, &key) != AEROSPIKE_OK) { fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);}If the record doesn’t exist, aerospike_key_remove() returns AEROSPIKE_ERR_RECORD_NOT_FOUND.
Deleting every record in a set
To delete all records in a set with one server-side command, use aerospike_truncate(), declared in aerospike/aerospike.h.
It is much faster than deleting records one at a time.
Pass NULL as the set name to truncate the whole namespace.
The last argument is a cutoff time in nanoseconds since the Unix epoch: only records last updated before it are deleted. Pass 0 to delete every record.
if (aerospike_truncate(&as, &err, NULL, "test", "test-set", 0) != AEROSPIKE_OK) { fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);}The call can return before the server finishes the truncation.