# Redis Save Migrate & Resume (SMR) on Kubernetes

{% hint style="warning" %}
This example is outdated. Please look at our other examples.
{% endhint %}

## Setup

Let's first set up a sample redis database on k8s. Create a namespace called `cedana-examples` and install `redis-example.yaml` , which can be found here: <https://github.com/cedana/cedana-helm-charts/tree/main/examples>.

```bash
kubectl create namespace cedana-examples
kubectl apply -f redis-example.yaml
```

Now let's port-forward the service on 127.0.0.1 and connect to the database:

```bash
kubectl port-forward service/redis -n cedana-examples 6379:6379
redis-cli -h 127.0.0.1
```

Lets store some data in the db:

```bash
HSET 'user:001' first_name 'John' last_name 'doe' dob '12-JUN-1970'
HSET 'user:002' first_name 'David' last_name 'Bloom' dob '03-MAR-1981'
```

Listing all the pods in the `cedana-examples` namespace using the `/list` endpoint gives us all the information we need to do a checkpoint and restore.

```bash
curl -X GET -H 'Content-Type: application/json' -d '{
  "root": "'$ROOT'"
}' $CONTROLLER_URL:1324/list/cedana-examples
```

Great! Now its time to checkpoint the container. Lets set the necessary environment variables before we proceed, which were present in the output of the `/list` endpoint. The following variables should work on most default containerd clusters.

```bash
export CHECKPOINT_CONTAINER=redis \
export CHECKPOINT_SANDBOX=redis-6b5bcbb6b6-tdb4p \
export RESTORE_CONTAINER=redis-restore \
export RESTORE_SANDBOX=redis-restore-c6c794b64-h7ccs \
export NAMESPACE=cedana-examples \
export CONTROLLER_URL=localhost \
export ROOT=/run/containerd/runc/k8s.io \
export CHECKPOINT_PATH=/tmp/ckpt-redis
```

## Checkpoint

```bash
curl -X POST -H "Content-Type: application/json" -d '{
  "checkpoint_data": {
    "container_name": "'$CHECKPOINT_CONTAINER'",
    "sandbox_name": "'$CHECKPOINT_SANDBOX'",
    "namespace": "'$NAMESPACE'",
    "checkpoint_path": "'$CHECKPOINT_PATH'",
    "root": "'$ROOT'"
  }
}' http://$CONTROLLER_URL:1324/checkpoint
```

## Restore

Once this completes, we need a new pod to restore the redis checkpoint into - effectively acting as a sleeping pod that we morph into a restored redis pod. We do this to avoid colliding with Kubernetes' scheduling and state management, so the users have full control over when pods are being restored.

```bash
k apply -f redis-restore-example.yaml
```

Then, performing a restore is as simple as another `curl` call:

```bash
curl -X POST -H "Content-Type: application/json" -d '{
  "checkpoint_data": {
    "container_name": "'$RESTORE_CONTAINER'",
    "sandbox_name": "'$RESTORE_SANDBOX'",
    "namespace": "'$NAMESPACE'",
    "checkpoint_path": "'$CHECKPOINT_PATH'",
    "root": "'$ROOT'"
  }
}' http://$CONTROLLER_URL:1324/restore
```

Finally connect to redis-cli once again to check if the new restored container has the previously set data:

```bash
HGETALL user:001
HGETALL user:002
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cedana.ai/examples/redis-smr.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
