# Run a Zenoh storage and query example

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/)
- [Build scalable communication systems with Eclipse Zenoh](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/1_intro-zenoh/)
- [Get started with Zenoh on Raspberry Pi and Arm Linux](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/2_zenoh-install/)
- [Containerize and deploy Zenoh across multiple Raspberry Pi devices](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/3_zenoh-multinode/)
- [Run a simple Zenoh pub/sub example](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/4_zenoh-ex1-pubsub/)
- [Run a Zenoh storage and query example](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/5_zenoh-ex2-storagequery/)
- [Run a Zenoh queryable node for on-demand edge computation](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/6_zenoh-ex3-queryable/)
- [Run a Zenoh queryable with parameterized Rust computation](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/7_zenoh-querycomp/)
- [Next Steps](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/_next-steps/)

## Query historical data using Zenoh’s storage engine
This example demonstrates Zenoh’s data storage and query model which enables nodes to retrieve previously published values - even after the original publisher goes offline.

Building on the previous pub/sub example, you’ll now run a lightweight Zenoh daemon that stores key–value pairs in memory. Then, you’ll publish data with `z_put` and retrieve it using `z_get`.

This pattern is ideal for robotics and IIoT scenarios where devices intermittently connect or request snapshots of remote state.

For example, in a warehouse or factory:
- Robots can periodically publish position, temperature, or battery level.
- A central system or peer node can later query these values on demand.

Unlike Pub/Sub, which requires live, real-time message exchange, Zenoh’s storage and query model enables asynchronous access to data that was published earlier, even if the original publisher is no longer online.

In this example, you’ll run the `zenohd` daemon with in-memory storage and use `z_put` to publish data and `z_get` to retrieve it.

This is especially useful for distributed systems where nodes may intermittently connect or request snapshots of state from peers.

## Start the Zenoh daemon with in-memory storage
On one Raspberry Pi, launch the Zenoh daemon with a configuration that enables in-memory storage for keys in the `demo/example/**` directory.

```
cd ~/zenoh/target/release/
./zenohd --cfg='plugins/storage_manager/storages/demo:{key_expr:"demo/example/**",volume:"memory"}' &
```

This starts the Zenoh daemon with in-memory storage support.

You should see log messages indicating that the storage_manager plugin is loaded.

If port 7447 is already in use, either stop any previous Zenoh processes or configure a custom port using the `listen.endpoints.router` setting.

## Publish a value
On the 2nd Raspberry Pi device, use `z_put` to send a key-value pair that will be handled by the `zenohd` storage.

```
cd ~/zenoh/target/release/examples
./z_put -k demo/example/test1 -p "Hello from storage!"
```

This command stores the string `Hello from storage!` under the key demo/example/test1.

## Query the stored value
Back on the first Raspberry Pi, you can now query the stored data from any Zenoh connected node.

```
cd ~/zenoh/target/release/examples
./z_get -s demo/example/test1
```

You should see an output similar to:
```
Sending Query 'demo/example/test1'..
>> Received ('demo/example/test1': 'Hello from storage!')
```

The result is shown below:

![Image Alt Text:Animated terminal demonstration showing z_put publishing a value to Zenoh storage on one device and z_get retrieving the stored value from another device, illustrating asynchronous data access across nodes](https://learn.arm.com/learning-paths/cross-platform/zenoh-multinode-ros2/zenoh_ex2.gif)
_Figure 2: Storage and Query_

If you have more than two Raspberry Pi devices, you can run the `z_get` command on a third device to validate that storage queries work seamlessly across a multi-node setup.

This example shows how Zenoh’s storage with query model supports asynchronous data access and resilient state-sharing - critical capabilities in robotics and industrial IoT systems where network connectivity may be intermittent or system components loosely coupled.

## What’s next?
Now that you’ve seen how Zenoh handles pub/sub and storage-based queries, you’re ready to build reactive and intelligent edge nodes.

In the next example, you’ll implement a **Zenoh queryable** that responds to runtime parameters, such as battery level and temperature, by computing and returning a real-time health score. This showcases how Zenoh supports on-demand edge computation without needing to pre-store data.
