Skip to content

Commit

Permalink
adding redis to local development setup, and adding a host-name refer…
Browse files Browse the repository at this point in the history
…ence in .env for it
  • Loading branch information
heckj committed Jan 4, 2025
1 parent ff67a00 commit ff251a8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.development.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DATABASE_PORT=6432
DATABASE_NAME=spi_dev
DATABASE_USERNAME=spi_dev
DATABASE_PASSWORD=xxx
REDIS_HOST=localhost
1 change: 1 addition & 0 deletions .env.testing.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DATABASE_PORT=5432
DATABASE_NAME=spi_test
DATABASE_USERNAME=spi_test
DATABASE_PASSWORD=xxx
REDIS_HOST=localhost
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ ingest:
analyze:
swift run Run analyze --limit 1

db-up: db-up-dev db-up-test
redis-up-dev:
docker run --name spi_redis -p 6379:6379 -d redis/redis-stack:7.4.0-v1

redis-down-dev:
docker rm -f spi_redis

db-up: db-up-dev db-up-test redis-up-dev

db-up-dev:
docker run --name spi_dev -e POSTGRES_DB=spi_dev -e POSTGRES_USER=spi_dev -e POSTGRES_PASSWORD=xxx -p 6432:5432 -d postgres:16-alpine
Expand All @@ -111,7 +117,7 @@ db-up-test:
-d \
postgres:13-alpine

db-down: db-down-dev db-down-test
db-down: db-down-dev db-down-test redis-down-dev

db-down-dev:
docker rm -f spi_dev
Expand Down
6 changes: 5 additions & 1 deletion Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public func configure(_ app: Application) async throws -> String {

// Setup Redis connection
do {
app.redis.configuration = try RedisConfiguration(hostname: "redis")
if let redisHost = Environment.get("REDIS_HOST") {
app.redis.configuration = try RedisConfiguration(hostname: redisHost)
} else {
app.logger.warning("REDIS_HOST not set, caching disabled.")
}
} catch {
app.logger.warning("Failed to configure Redis, caching disabled. Error: \(error)")
}
Expand Down
1 change: 1 addition & 0 deletions app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ x-shared: &shared
TWITTER_API_SECRET: ${TWITTER_API_SECRET}
TWITTER_ACCESS_TOKEN_KEY: ${TWITTER_ACCESS_TOKEN_KEY}
TWITTER_ACCESS_TOKEN_SECRET: ${TWITTER_ACCESS_TOKEN_SECRET}
REDIS_HOST: ${REDIS_HOST}
volumes:
- checkouts:/checkouts

Expand Down

0 comments on commit ff251a8

Please sign in to comment.