Skip to content

Commit 2a44c47

Browse files
committed
add valkey example as redis alternative
1 parent b0cfe92 commit 2a44c47

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ POSTGRES_USER=user
99
POSTGRES_PASSWORD=secret
1010

1111
# Redis
12-
REDIS_HOST=redis
12+
REDIS_HOST=inmemory
1313
REDIS_PORT=6379
1414
REDIS_DB=2
1515

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ model-generate: ## generate sqlalchemy models from database
6565
.PHONY: docker-up-granian
6666
docker-up-granian: ## Run project with compose and granian
6767
docker compose -f granian-compose.yml up --remove-orphans
68+
docker compose -f valkey-compose.yml up --remove-orphans

compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ services:
4444
timeout: 5s
4545
retries: 5
4646

47-
redis:
47+
inmemory:
4848
image: redis:latest
49-
container_name: fsap_redis
49+
container_name: fsap_inmemory
5050
ports:
5151
- "6379:6379"
5252
env_file:

granian-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ services:
3838
timeout: 5s
3939
retries: 5
4040

41-
redis:
41+
inmemory:
4242
image: redis:latest
43-
container_name: fsap_redis
43+
container_name: fsap_inmemory
4444
ports:
4545
- "6379:6379"
4646
env_file:

valkey-compose.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
services:
2+
app:
3+
container_name: fsap_app
4+
build: .
5+
env_file:
6+
- .env
7+
- .secrets
8+
command: bash -c "
9+
uvicorn app.main:app
10+
--log-config ./logging-uvicorn.json
11+
--host 0.0.0.0 --port 8080
12+
--lifespan=on --use-colors --loop uvloop --http httptools
13+
--reload --log-level debug
14+
"
15+
volumes:
16+
- .:/home/code
17+
ports:
18+
- "8080:8080"
19+
depends_on:
20+
- db
21+
- valkey
22+
23+
db:
24+
container_name: fsap_db
25+
build:
26+
context: ./db
27+
dockerfile: Dockerfile
28+
volumes:
29+
- fastapi_postgres_data:/var/lib/postgresql/data
30+
env_file:
31+
- .env
32+
ports:
33+
- 5432:5432
34+
environment:
35+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
36+
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
37+
- POSTGRES_DB=${POSTGRES_DB?Variable not set}
38+
healthcheck:
39+
test:
40+
[
41+
"CMD-SHELL", "pg_isready -d $POSTGRES_DB -U $POSTGRES_USER"
42+
]
43+
interval: 5s
44+
timeout: 5s
45+
retries: 5
46+
47+
inmemory:
48+
image: valkey/valkey:latest
49+
container_name: fsap_inmemory
50+
ports:
51+
- "6379:6379"
52+
env_file:
53+
- .env
54+
entrypoint: valkey-server --loglevel verbose
55+
56+
volumes:
57+
fastapi_postgres_data: {}

0 commit comments

Comments
 (0)