Files
vt/utils/cache.go
2025-11-06 11:46:35 +01:00

36 lines
802 B
Go

package utils
import (
"context"
"fmt"
"strconv"
glide "github.com/valkey-io/valkey-glide/go/v2"
"github.com/valkey-io/valkey-glide/go/v2/config"
)
func SetupCache(host, port, user, pass string) (*glide.Client, bool) {
p, err := strconv.Atoi(port)
if err != nil {
fmt.Println("VALKEY_PORT is not a number")
return nil, false
}
config := config.NewClientConfiguration().WithAddress(&config.NodeAddress{Host: host, Port: p}).WithCredentials(config.NewServerCredentials(user, pass))
client, err := glide.NewClient(config)
if err != nil {
fmt.Println("There was an error: ", err)
return nil, false
}
res, err := client.Ping(context.Background())
if err != nil {
fmt.Println("There was an error: ", err)
return nil, false
}
fmt.Println(res) // PONG
return client, true
}