Skip to content

Authentication

By default, when connecting to Valkey, Valkey GLIDE operates in an unauthenticated mode.

Valkey GLIDE also offers support for an authenticated connection mode.

In authenticated mode, you have the following options:

  • Use both a username and password, which is recommended and configured through ACLs on the server.
  • Use a password only, which is applicable if the server is configured with the requirepass setting.

To provide the necessary authentication credentials to the client, you can use the ServerCredentials struct.

See the Dynamic Authentication section for a detailed explanation about using ACLs with GLIDE.

Example: Connecting with Username and Password to a Cluster

Section titled “Example: Connecting with Username and Password to a Cluster”
import (
glide "github.com/valkey-io/valkey-glide/go/v2"
"github.com/valkey-io/valkey-glide/go/v2/config"
)
func ConnectClusterWithCredentials() {
myConfig := config.NewClusterClientConfiguration().
WithAddress(&config.NodeAddress{Host: "address.example.com", Port: 6379}).
WithCredentials(config.NewServerCredentials("user1", "passwordA"))
client, err := glide.NewClusterClient(myConfig)
}

Example: Connecting with Username and Password to a Standalone

Section titled “Example: Connecting with Username and Password to a Standalone”
import (
glide "github.com/valkey-io/valkey-glide/go/v2"
"github.com/valkey-io/valkey-glide/go/v2/config"
)
func ConnectStandaloneWithCredentials() {
myConfig := config.NewClientConfiguration().
WithAddress(&config.NodeAddress{Host: "primary.example.com", Port: 6379}).
WithCredentials(config.NewServerCredentials("user1", "passwordA"))
client, err := glide.NewClient(myConfig)
}

Starting with GLIDE 2.2+ built-in support for AWS Identity and Access Management (IAM) authentication is available when connecting to Amazon ElastiCache and MemoryDB clusters. This feature automatically handles token generation and rotation, making it simple to maintain secure connections.

See the IAM Authentication with GLIDE section for a detailed explanation.