Skip to content

Commit

Permalink
feat: add REDIS_PASSWORD with settings and redis clients
Browse files Browse the repository at this point in the history
  • Loading branch information
RV committed Oct 29, 2024
1 parent bc5801c commit 96a8cfc
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ POSTGRES_PORT=5432
API_PORT=8000
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=bloom
REDIS_CACHE_EXPIRATION=900
SPIRE_TOKEN=
SLACK_URL=
Expand Down
1 change: 1 addition & 0 deletions backend/bloom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Settings(BaseSettings):

redis_host: str = Field(default='localhost')
redis_port: int = Field(default=6379)
redis_password: str = Field(default='bloom',min_length=1)
redis_cache_expiration: int = Field(default=900)

logging_level:str=Field(
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/routers/v1/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bloom.dependencies import (X_API_KEY_HEADER,check_apikey)

router = APIRouter()
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0)
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0, password=settings.redis_password)

@router.get("/cache/all/flush")
async def cache_all_flush(request:Request,key: str = Depends(X_API_KEY_HEADER)):
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/routers/v1/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from bloom.domain.metrics import TotalTimeActivityTypeRequest

router = APIRouter()
rd = Redis(host=settings.redis_host, port=settings.redis_port, db=0)
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0, password=settings.redis_password)

@router.get("/metrics/vessels-in-activity",
response_model=list[ResponseMetricsVesselInActivitySchema])
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/routers/v1/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from bloom.config import settings

router = APIRouter()
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0)
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0, password=settings.redis_password)

@router.get("/ports")
async def list_ports( request:Request,
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/routers/v1/vessels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
X_API_KEY_HEADER,check_apikey)

router = APIRouter()
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0)
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0, password=settings.redis_password)

@router.get("/vessels")
async def list_vessels(nocache:bool=False,key: str = Depends(X_API_KEY_HEADER)):
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/routers/v1/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
X_API_KEY_HEADER,check_apikey)

router = APIRouter()
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0)
rd = redis.Redis(host=settings.redis_host, port=settings.redis_port, db=0, password=settings.redis_password)

@router.get("/zones")
async def list_zones(request:Request,nocache:bool=False,key: str = Depends(X_API_KEY_HEADER)):
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ services:
container_name: bloom_redis
hostname: bloom-redis
restart: always
command:
- sh
- -c
- redis-server --requirepass ${REDIS_PASSWORD}
ports:
- ${REDIS_PORT:-6379}:6379
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis}
- REDIS_PORT=${REDIS_PORT:-6379}
volumes:
- bloom-redis:/data
- ./docker/redis/redis.conf:/usr/local/etc/redis/redis.conf
networks:
- bloom_net

Expand Down

0 comments on commit 96a8cfc

Please sign in to comment.