# Redis


import { Tabs, TabsContent, TabsList, TabsTrigger } from "zudoku/ui/Tabs"

{/* vale off */}
This guide shows you how to use [Redis](https://redis.io), an open source in-memory storage, used as a distributed, in-memory key–value database, cache and message broker, with optional durability.

To run it, follow these steps:

1. Install the CLI.
   Use the [unikraft CLI](/cli/unikraft) or the legacy [kraft CLI](https://unikraft.org/docs/cli/install).
   You need a [BuildKit](https://github.com/moby/buildkit) builder. The easiest way to get one is via [Docker](https://docs.docker.com/engine/install/).
   Alternatively, you can also directly set up and use BuildKit, see the [quick start](https://github.com/moby/buildkit#quick-start).

2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/redis7.2/` directory:

```bash
git clone https://github.com/unikraft-cloud/examples
cd examples/redis7.2/
```

Make sure to log into Unikraft Cloud and pick a [metro](/platform/metros) close to you.
This guide uses `fra` (Frankfurt, 🇩🇪):

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft login
```

```bash title="kraft"
# Set Unikraft Cloud access token
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra
```

</CodeTabs>

When done, invoke the following command to deploy this app on Unikraft Cloud:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft build . --output <my-org>/redis72:latest
unikraft run --scale-to-zero policy=off --metro fra -p 6379:6379/tls -m 512M --image <my-org>/redis72:latest
```

```bash title="kraft"
kraft cloud deploy --scale-to-zero off -p 6379:6379/tls -M 512Mi .
```

</CodeTabs>

The output shows the instance address and other details:

<CodeTabs syncKey="cli">

```ansi title="unikraft"
metro:        fra
name:         redis72-alb4r
uuid:         d3c3141b-97b2-4e1d-87ae-39e4f14ab49e
state:        [92mstarting[0m
image:        <my-org>/redis72
resources:
  memory:     512MiB
  vcpus:      1
service:
  uuid:       7a4f2b3c-1d8e-4a92-b3f5-e6c1d2a3b4e5
  name:       rough-wind-8vxrd1ms
  domains:
  - fqdn:     rough-wind-8vxrd1ms.fra.unikraft.app
networks:
- uuid:       9b5e1f8d-3c2a-7b46-d1e9-f2a3b4c5d6e7
  private-ip: 10.0.3.2
  mac:        12:b0:4e:20:b3:e7
timestamps:
  created:    just now
```

```ansi title="kraft"
[90m[[0m[92m●[0m[90m][0m Deployed successfully!
 [90m│[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mname[0m: redis72-alb4r
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90muuid[0m: d3c3141b-97b2-4e1d-87ae-39e4f14ab49e
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmetro[0m: https://api.fra.unikraft.cloud/v1
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mstate[0m: [92mstarting[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mdomain[0m: https://rough-wind-8vxrd1ms.fra.unikraft.app
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mimage[0m: oci://unikraft.io/<my-org>/redis72@sha256:9665c51faf7deb538cf7907b012b55700cad08cd391f5ba099d95d018c8da7d
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmemory[0m: 512 MiB
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mservice[0m: rough-wind-8vxrd1ms
 [90m├[0m[90m─[0m [90mprivate fqdn[0m: redis72-alb4r.internal
 [90m└[0m[90m─[0m[90m─[0m[90m─[0m [90mprivate ip[0m: 10.0.3.2
```

</CodeTabs>

In this case, the instance name is `redis72-alb4r` which is different for every run.

To test the deployment, first forward the port using `socat`:

```bash
socat TCP-LISTEN:6379,fork OPENSSL:rough-wind-8vxrd1ms.fra.unikraft.app:6379,verify=0
```

Then, from another console, you can now use the `redis-benchmark` client to connect to Redis, for example:

```console
redis-benchmark -t ping,set,get -n 10000
```

You should see output like:

```ansi
====== PING_INLINE ======
  10000 requests completed in 32.03 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1
  host configuration "save":
  host configuration "appendonly": no
  multi-thread: no

0.01% <= 138 milliseconds
0.05% <= 139 milliseconds
2.34% <= 140 milliseconds
4.49% <= 141 milliseconds
8.57% <= 142 milliseconds
16.06% <= 143 milliseconds
21.83% <= 144 milliseconds
26.25% <= 145 milliseconds
34.54% <= 146 milliseconds
...
```

To disconnect, kill the `socat` command with ctrl-C.

> **Note:**
> This guide uses `socat` for port forwarding only when a service doesn't support TLS and isn't HTTP-based (TLS/SNI determines the correct instance to send traffic to).
> Also note that port forwarding isn't needed when connecting via an instance's private IP/FQDN.
> For example, when a Redis instance serves as a cache server to
> another instance that acts as a frontend and which **does** support TLS.

You can list information about the instance by running:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances list
```

```bash title="kraft"
kraft cloud instance list
```

</CodeTabs>

<CodeTabs syncKey="cli">

```ansi title="unikraft"
[1mMETRO[0m  [1mNAME[0m           [1mSTATE[0m    [1mIMAGE[0m              [1mARGS[0m  [1mMEMORY[0m  [1mVCPUS[0m  [1mFQDN[0m                                  [1mCREATED[0m
fra    redis72-alb4r  [92mrunning[0m  <my-org>/redis72        512MiB  1      rough-wind-8vxrd1ms.fra.unikraft.app  1 minute ago
```

```ansi title="kraft"
[1mNAME[0m           [1mFQDN[0m                                  [1mSTATE[0m    [1mSTATUS[0m        [1mIMAGE[0m                                           [1mMEMORY[0m   [1mVCPUS[0m  [1mARGS[0m  [1mBOOT TIME[0m
redis72-alb4r  rough-wind-8vxrd1ms.fra.unikraft.app  [92mrunning[0m  1 minute ago  oci://unikraft.io/<my-org>/redis72@sha256:...  512 MiB  1            26.13 ms
```

</CodeTabs>

When done, you can remove the instance:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances delete redis72-alb4r
```

```bash title="kraft"
kraft cloud instance remove redis72-alb4r
```

</CodeTabs>

## Customize your app

To customize the app, update the files in the repository, listed below:

* `Kraftfile`: the Unikraft Cloud specification, including command-line arguments
* `Dockerfile`: In case you need to add files to your instance's rootfs

## Learn more

Use the `--help` option for detailed information on using Unikraft Cloud:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft --help
```

```bash title="kraft"
kraft cloud --help
```

</CodeTabs>

Or visit the [CLI Reference](/cli/unikraft) or the [legacy CLI Reference](/cli/kraft/overview).
{/* vale on */}
