A prebuild golang server to work with redis db.
466
The project is saved in github.
The Redis DB must be up and running. It can be locally hosted, Redis docker image or cloud-based.
Use docker-compose to pass the Redis DB details to the server.
Set the environment variable of the redis-db:
Note If the password is an empty string "", don't send the empty string.
REDIS_DB_PASSWORD=
It will take that as an empty string.
docker pull schadokar/redis-go-server
version: "2"
services:
redis-db:
image: redis:alpine
ports:
- 6379:6379
container_name: redis-db
redis-go-server:
image: schadokar/redis-go-server:latest
environment:
- REDIS_DB_URL=redis-db:6379
- REDIS_DB_PASSWORD=
- REDIS_DB=0
ports:
- 8080:8080
depends_on:
- redis-db
container_name: redis-go-server
First, we're pulling the redis:alpine image and running it as redis-db container.
The second image is schadokar/redis-go-server which is running as redis-go-server container.
Check the environment variables.
There are 3 endpoints of the server:
{
"key": "strongest-avenger",
"value": "thor"
}
docker-compose -f <file-path> up -d
Output
docker-compose -f ./docker-compose.yaml up -d
Creating network "deployments_default" with the default driver
Creating redis-db ... done
Creating redis-go-server ... done
cURLcurl -d '{"key":"strongest-avenger","value":"thor"}' -X POST http://localhost:8080/set
Output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 64 100 22 100 42 687 1312 --:--:-- --:--:-- --:--:-- 2000 "Successfully Saved!"
strongest-avengercurl -X GET http://localhost:8080/get/strongest-avenger
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7 100 7 0 0 148 0 --:--:-- --:--:-- --:--:-- 148 "thor"
curl -X GET http://localhost:8080/get
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 22 100 22 0 0 1466 0 --:--:-- --:--:-- --:--:-- 1466 ["strongest-avenger"]
Content type
Image
Digest
Size
7.5 MB
Last updated
almost 7 years ago
docker pull schadokar/redis-go-server