Go and Redis HTTP Server
This guide explains how to create and deploy a Go app with a Redis database. To run this example, follow these steps:
-
Install the CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.
The unikraft CLI is the current standard, while kraft is the legacy version. Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
-
Clone the
examplesrepository andcdinto theexamples/httpserver-go1.22-redisdirectory:
Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
Deploy Redis
First, deploy the Redis instance.
Redis is an internal service (not publicly accessible), reached via the go122-redis.internal domain.
The Redis password is set at runtime via the REDIS_PASSWORD environment variable (defaults to unikraft if not provided).
Make sure to replace <my-org> with your username / org-name.
The output shows the Redis instance details:
Deploy Go HTTP Server
Next, deploy the Go HTTP server.
It connects to Redis using the REDIS_ADDR and REDIS_PASS environment variables:
The output shows the instance address and other details:
In this case, the instance names are httpserver-go-122-redis-db-2xc9u and httpserver-go-122-redis-app-bnnnc.
They're different for each run.
To set a value in Redis via the Go server, use the URL from the fqdn field:
Code
Code
You can then retrieve the value:
Code
Code
You can list information about the instances by running:
Clean up
When done, remove the instances:
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference or the legacy CLI Reference.