Delete
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
This example deletes the key mykey from the namespace test in the set myset:
let key = as_key!("test", "test", "mykey");match client.delete(&WritePolicy::default(), &key).await { Ok(true) => println!("Record deleted"), Ok(false) => println!("Record did not exist"), Err(err) => println!("Error deleting record: {}", err),};📖 API reference:
Client::delete|WritePolicy::default
Delete every record in a set
To delete all the records in a set with a single server-side call, use Client::truncate. Unlike Client::delete, it takes an AdminPolicy, and it takes the namespace and set name instead of a key. The last argument is a cutoff time in nanoseconds since the Unix epoch. 0 deletes every record in the set:
use aerospike::AdminPolicy;
client.truncate(&AdminPolicy::default(), "test", "myset", 0).await?;📖 API reference:
Client::truncate|AdminPolicy
truncate returns Result<()>. It doesn’t return a count of the records it deleted.
To delete only the records that were last updated before a given time, pass that time as the last argument. Records updated at or after the cutoff stay:
use std::time::{SystemTime, UNIX_EPOCH};
let cutoff = SystemTime::now().duration_since(UNIX_EPOCH) .expect("system clock is before the Unix epoch") .as_nanos() as i64;client.truncate(&AdminPolicy::default(), "test", "myset", cutoff).await?;