Bulk commit: November work
This commit is contained in:
35
utils/cache.go
Normal file
35
utils/cache.go
Normal file
@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user