# Redis

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

{/* vale off */}
{/* THIS FILE WAS AUTOGENERATED FROM THE PUBLIC EXAMPLE REPOSITORY. DO NOT EDIT THIS FILE DIRECTLY. */}


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 [unikraft CLI](/cli).
   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, 🇩🇪):

```bash
unikraft login
```

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

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

The output shows the instance address and other details:

```ansi
[1mmetro[22m:        fra
[1mname[22m:         redis72-alb4r
[1muuid[22m:         d3c3141b-97b2-4e1d-87ae-39e4f14ab49e
[1mstate[22m:        [38;2;144;161;185mstarting[0m
[1mimage[22m:        <my-org>/redis72
[1mresources[22m:
[3m  memory[23m:     512MiB
[3m  vcpus[23m:      1
[1mservice[22m:
[3m  uuid[23m:       7a4f2b3c-1d8e-4a92-b3f5-e6c1d2a3b4e5
[3m  name[23m:       rough-wind-8vxrd1ms
[3m  domains[23m:
[3m  - fqdn[23m:     rough-wind-8vxrd1ms.fra.unikraft.app
[1mnetworks[22m:
[3m- uuid[23m:       9b5e1f8d-3c2a-7b46-d1e9-f2a3b4c5d6e7
[3m  private-ip[23m: 10.0.3.2
[3m  mac[23m:        12:b0:4e:20:b3:e7
[1mtimestamps[22m:
[3m  created[23m:    just now
```

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:

```bash
unikraft instances list
```

```ansi
[1mMETRO[22m  [1mNAME[22m           [1mSTATE[22m    [1mIMAGE[22m              [1mARGS[22m  [1mMEMORY[22m  [1mVCPUS[22m  [1mFQDN[22m                                  [1mCREATED[22m
fra    redis72-alb4r  [38;2;0;188;125mrunning[0m  <my-org>/redis72        512MiB  1      rough-wind-8vxrd1ms.fra.unikraft.app  1 minute ago
```

When done, you can remove the instance:

```bash
unikraft instances delete redis72-alb4r
```

## 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:

```bash
unikraft --help
```

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