Skip to content

Commit ee29b7b

Browse files
committed
Set up Redis connection
1 parent ab2d131 commit ee29b7b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/App/configure.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
import Fluent
1616
import FluentPostgresDriver
17+
import Redis
1718
import Vapor
1819

20+
1921
@discardableResult
2022
public func configure(_ app: Application) async throws -> String {
2123
#if DEBUG && os(macOS)
@@ -49,6 +51,7 @@ public func configure(_ app: Application) async throws -> String {
4951
// This parameter could also be made configurable via an env variable.
5052
let maxConnectionsPerEventLoop = 3
5153

54+
// Setup database connection
5255
guard
5356
let host = Environment.get("DATABASE_HOST"),
5457
let port = Environment.get("DATABASE_PORT").flatMap(Int.init),
@@ -75,6 +78,13 @@ public func configure(_ app: Application) async throws -> String {
7578
sqlLogLevel: .debug),
7679
as: .psql)
7780

81+
// Setup Redis connection
82+
do {
83+
app.redis.configuration = try RedisConfiguration(hostname: "redis")
84+
} catch {
85+
app.logger.warning("Failed to configure Redis, caching disabled. Error: \(error)")
86+
}
87+
7888
do { // Migration 001 - schema 1.0
7989
app.migrations.add(CreatePackage())
8090
app.migrations.add(CreateRepository())

0 commit comments

Comments
 (0)