package redisdb import ( "context" "fmt" "github.com/go-redis/redis/v8" ) type Server struct { rdb *redis.Client } var r *Server // Connect ... func Connect(uri, password, server string) (*Server, error) { ctx := context.Background() rdb := redis.NewClient(&redis.Options{ Addr: uri, Password: password, DB: 0, // use default DB }) // Ping _, err := rdb.Ping(ctx).Result() if err != nil { fmt.Printf("[redisdb] connect to %s error: %s \n", uri, err.Error()) return nil, err } // assign data r = &Server{rdb: rdb} fmt.Printf("⚡️[natsio]: connected to %s \n", uri) return r, nil }