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 }