Skip to content

Commit

Permalink
Merge pull request #129 from porters-xyz/fix-redis-railway
Browse files Browse the repository at this point in the history
Adding logging to diagnose redis connection issues
  • Loading branch information
plor authored Feb 27, 2024
2 parents dd285b0 + 42ecf74 commit 4e9c723
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gateway/db/cache.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package db

import (
"context"
"log"
"os"
"sync"

Expand All @@ -19,9 +21,22 @@ func getClient() *redis.Client {
// TODO figure out which redis instance to connect to
client = redis.NewClient(&redis.Options{
Addr: os.Getenv("REDIS_ADDR"),
Username: os.Getenv("REDIS_USER"),
Password: os.Getenv("REDIS_PASSWORD"),
DB: 0,
})
log.Println("redis client:", client)
})
return client
}

func healthcheck() {
client := getClient()
ctx := context.Background()
status, err := client.Ping(ctx).Result()
if err != nil {
log.Println("Error in redis connection", err)
} else {
log.Println("redis:", status)
}
}
3 changes: 3 additions & 0 deletions gateway/db/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func ConnectSync() *Sync {
listener := pq.NewListener(connStr, 10*time.Second, 2*time.Minute, sync.eventListener)
sync.listener = listener

// Check redis
healthcheck()

return sync
}

Expand Down

0 comments on commit 4e9c723

Please sign in to comment.