Primary index
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
The Aerospike Rust client lets you query all records in a specified namespace and set.
Querying records
This example counts the number of records in the query result:
use aerospike::{Bins, Client, ClientPolicy, Error, QueryPolicy, Statement};use aerospike::query::PartitionFilter;use futures::stream::StreamExt;
#[tokio::main]async fn main() -> Result<(), Error> { let hosts = std::env::var("AEROSPIKE_HOSTS") .unwrap_or_else(|_| "localhost:3000".to_string()); let client = Client::new(&ClientPolicy::default(), &hosts).await?;
let policy = QueryPolicy::default(); let stmt = Statement::new("test", "demo", Bins::None);
let rs = client.query(&policy, PartitionFilter::all(), stmt).await?; let mut stream = rs.into_stream();
let mut count: usize = 0; while let Some(result) = stream.next().await { match result { Ok(_record) => count += 1, Err(err) => println!("Error during scan: {}", err), } } println!("Records: {}", count);
client.close().await?; Ok(())}📖 API reference:
Client::new|Client::query|Statement::new|PartitionFilter::all|Recordset::into_stream
Reading bins from query results
Each Ok(record) in the stream is a Record:
record.binsis anIndexMap<String, Value>(not aHashMap, and not anOption). It supports the same.get()method, so read a bin withrecord.bins.get("name"); unlikeHashMap, iteration order matches the order the server returned the bins.record.keyisOption<Key>. Print it with{:?}(for exampleprintln!("{:?}", record.key)), not{}.
while let Some(result) = stream.next().await { match result { Ok(record) => { if let Some(name) = record.bins.get("name") { println!("name: {name}"); } } Err(err) => println!("Error during query: {err}"), }}The query executes asynchronously. If an error occurs while executing the query, parallel query tasks to other nodes are terminated and the error propagates back through the record stream.