From 42ecf74b6e0a2de28fb9c35d8d607456d20e7b7c Mon Sep 17 00:00:00 2001 From: plor Date: Tue, 27 Feb 2024 12:37:51 -0600 Subject: [PATCH] Adding logging to diagnose redis connection issues --- gateway/db/cache.go | 15 +++++++++++++++ gateway/db/sync.go | 3 +++ 2 files changed, 18 insertions(+) diff --git a/gateway/db/cache.go b/gateway/db/cache.go index a966b52d..93b433d4 100644 --- a/gateway/db/cache.go +++ b/gateway/db/cache.go @@ -1,6 +1,8 @@ package db import ( + "context" + "log" "os" "sync" @@ -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) + } +} diff --git a/gateway/db/sync.go b/gateway/db/sync.go index cbf33175..80f89ce6 100644 --- a/gateway/db/sync.go +++ b/gateway/db/sync.go @@ -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 }