Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding logging to diagnose redis connection issues #129

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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