Skip to content

Getting Started

The release of Valkey GLIDE was tested on the following platforms:

Linux:

  • Ubuntu 20 (x86_64/amd64 and arm64/aarch64)
  • Amazon Linux 2 (AL2) and 2023 (AL2023) (x86_64)

macOS:

  • macOS 14.7 (Apple silicon/aarch_64)
  • macOS 13.7 (x86_64/amd64)

Valkey GLIDE Go supports Go version 1.22 and above.

To install Valkey GLIDE in your Go project, follow these steps:

  1. Open your terminal in your project directory.
  2. Execute the commands below:
    Terminal window
    $ go get github.com/valkey-io/valkey-glide/go/v2
    $ go mod tidy
  3. After installation, you can start up a Valkey server and run one of the examples in Basic Examples.
package main
import (
"context"
"fmt"
glide "github.com/valkey-io/valkey-glide/go/v2"
"github.com/valkey-io/valkey-glide/go/v2/config"
)
func main() {
host := "localhost"
port := 6379
config := config.NewClientConfiguration().
WithAddress(&config.NodeAddress{Host: host, Port: port})
client, err := glide.NewClient(config)
if err != nil {
fmt.Println("There was an error: ", err)
return
}
res, err := client.Ping(context.Background())
if err != nil {
fmt.Println("There was an error: ", err)
return
}
fmt.Println(res) // PONG
client.Close()
}
package main
import (
"context"
"fmt"
glide "github.com/valkey-io/valkey-glide/go/v2"
"github.com/valkey-io/valkey-glide/go/v2/config"
)
func main() {
host := "localhost"
port := 7001
config := config.NewClusterClientConfiguration().
WithAddress(&config.NodeAddress{Host: host, Port: port})
client, err := glide.NewClusterClient(config)
if err != nil {
fmt.Println("There was an error: ", err)
return
}
res, err := client.Ping(context.Background())
if err != nil {
fmt.Println("There was an error: ", err)
return
}
fmt.Println(res) // PONG
client.Close()
}

Full Example with All Client Configurations

Section titled “Full Example with All Client Configurations”
import (
glide "github.com/valkey-io/valkey-glide/go/v2"
"github.com/valkey-io/valkey-glide/go/v2/config"
)
func FullConfigExample() {
// GlideClient example
standaloneConfig := config.NewClientConfiguration().
WithAddress(&config.NodeAddress{Host: "primary.example.com", Port: 6379}).
WithClientName("some client name").
WithCredentials(config.NewServerCredentials("user1", "passwordA")).
WithDatabaseId(1).
WithReadFrom(config.PreferReplica).
WithReconnectStrategy(config.NewBackoffStrategy(5, 10, 50)).
WithRequestTimeout(500).
WithUseTLS(true)
standaloneClient, err := glide.NewClient(standaloneConfig)
// GlideClusterClient example
clusterConfig := config.NewClusterClientConfiguration().
WithAddress(&config.NodeAddress{Host: "address.example.com", Port: 6379}).
WithClientName("some client name").
WithCredentials(config.NewServerCredentials("user1", "passwordA")).
WithReadFrom(config.PreferReplica).
WithRequestTimeout(500).
WithUseTLS(true)
clusterClient, err := glide.NewClusterClient(clusterConfig)
}

For more code examples please refer to examples.md.

Development instructions for local building & testing the package are in the developer section