Getting Started
System Requirements
Section titled “System Requirements”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)
GO supported versions
Section titled “GO supported versions”Valkey GLIDE Go supports Go version 1.22 and above.
Installation and Setup
Section titled “Installation and Setup”To install Valkey GLIDE in your Go project, follow these steps:
- Open your terminal in your project directory.
- Execute the commands below:
Terminal window $ go get github.com/valkey-io/valkey-glide/go/v2$ go mod tidy - After installation, you can start up a Valkey server and run one of the examples in Basic Examples.
Basic Examples
Section titled “Basic Examples”Standalone Example
Section titled “Standalone Example”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()}Cluster Example
Section titled “Cluster Example”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)}More Code Examples
Section titled “More Code Examples”For more code examples please refer to examples.md.
Building & Testing
Section titled “Building & Testing”Development instructions for local building & testing the package are in the developer section