---
title: "Read"
description: "Learn how to read all bins, specific bins, or record metadata using the Aerospike Rust client library."
---

# Read

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

To read a record from the database, the Aerospike Rust client library can:

-   Read all bins in a record.
-   Read specified bins in a record.
-   Read only the metadata of a record.

Each method returns a `Record` struct that contains the metadata and bins of the record.

## Read all bins in a record

This example reads all bins for a record. We match against `KeyNotFoundError` to handle missing records.

```rust
let key = as_key!("test", "myset", "mykey");

match client.get(&ReadPolicy::default(), &key, Bins::All).await {

    Ok(record)

        => println!("name={:?}", record.bins.get("name")),

    Err(Error::ServerError(ResultCode::KeyNotFoundError, ..))

        => println!("No such record: {}", key),

    Err(err)

        => println!("Error fetching record: {}", err),

}
```

> 📖 **API reference**: [`Client::get`](https://docs.rs/aerospike/latest/aerospike/struct.Client.html#method.get) | [`ReadPolicy::default`](https://docs.rs/aerospike/latest/aerospike/struct.ReadPolicy.html) | [`Bins`](https://docs.rs/aerospike/latest/aerospike/enum.Bins.html) | [`Error`](https://docs.rs/aerospike/latest/aerospike/enum.Error.html) | [`ResultCode`](https://docs.rs/aerospike/latest/aerospike/enum.ResultCode.html)

## Read specific bins of a record

This example only reads two bins from the record: `name` and `age`:

```rust
let key = as_key!("test", "test", "mykey");

match client.get(&ReadPolicy::default(), &key, ["name", "age"]).await {

    Ok(record) => {

        println!("name={:?}", record.bins.get("name"));

        println!("age={:?}", record.bins.get("age"));

    }

    Err(Error::ServerError(ResultCode::KeyNotFoundError, ..)) => {

        println!("No such record: {}", key);

    }

    Err(err) => {

        println!("Error fetching record: {}", err);

    }

}
```

> 📖 **API reference**: [`Client::get`](https://docs.rs/aerospike/latest/aerospike/struct.Client.html#method.get) | [`ReadPolicy::default`](https://docs.rs/aerospike/latest/aerospike/struct.ReadPolicy.html)

## Extract typed bin values

`record.bins` maps bin names to `aerospike::Value`. Use `TryFrom` to convert to Rust types:

```rust
let name = record

    .bins

    .get("name")

    .and_then(|v| String::try_from(v.clone()).ok())

    .unwrap_or_else(|| "unknown".to_string());
```

See [Reading bin values](https://aerospike.com/docs/develop/client/rust/data-types#reading-bin-values) in Supported data types for string, integer, and pattern-matching examples.

## Read record metadata

Use `Bins::None` to fetch only the record’s metadata. The following example retrieves the record’s remaining time-to-live:

```rust
let key = as_key!("test", "myset", "mykey");

match client.get(&ReadPolicy::default(), &key, Bins::None).await {

    Ok(record) => {

        match record.time_to_live() {

            None => println!("record never expires"),

            Some(duration) => println!("ttl: {} secs", duration.as_secs()),

        }

    }

    Err(Error::ServerError(ResultCode::KeyNotFoundError, ..)) => {

        println!("No such record: {}", key);

    }

    Err(err) => {

        println!("Error fetching record: {}", err);

    }

}
```

> 📖 **API reference**: [`Client::get`](https://docs.rs/aerospike/latest/aerospike/struct.Client.html#method.get) | [`Record::time_to_live`](https://docs.rs/aerospike/latest/aerospike/struct.Record.html#method.time_to_live)