Quick start
This guide will go over setting up a simple developement environment connected to a Valkey Docker instance.
Understanding GLIDE Clients
Section titled “Understanding GLIDE Clients”GLIDE provides two main client types:
GlideClient: For standalone Valkey instances.GlideClusterClient: For cluster deployments.
For this guide, we will use a standalone client to connect to a Valkey Docker instance.
Setting Up
Section titled “Setting Up”-
Follow the instructions on the Docker website to install Docker for your operating system.
-
Start a local Valkey server:
Terminal window # Pull and run Valkey serverdocker run -d --name valkey-server -p 6379:6379 valkey/valkey:latest# Verify it's runningdocker ps -
Verify connection with Valkey server:
Terminal window docker exec valkey-server valkey-cli ping# Expected output: PONG -
Install Valkey GLIDE
Terminal window # Install the latest versionpip3 install valkey-glide// Add to your `pom.xml`<dependencies><dependency><groupId>io.valkey</groupId><artifactId>valkey-glide</artifactId><version>2.0.1</version></dependency></dependencies>Terminal window # GLIDE includes TypeScript definitions out of the box.npm install @valkey/valkey-glideTerminal window # Initialize a new Go module (if needed)go mod init your-project-name# Install GLIDEgo get github.com/valkey-io/valkey-glide/go -
Finally, conect to Valkey using GLIDE and verify your installation.
import asynciofrom glide import GlideClient, NodeAddressasync def main():# Create client configurationclient = GlideClient([NodeAddress("localhost", 6379)])try:# Test the connectionresponse = await client.ping()# Valkey respond with PONGprint(f"Connected! Server responded: {response}")except Exception as e:print(f"Connection failed: {e}")finally:# Always close the clientawait client.close()# Run the async functionif __name__ == "__main__":asyncio.run(main())import glide.api.GlideClient;import glide.api.models.configuration.GlideClientConfiguration;import glide.api.models.configuration.NodeAddress;public class ConnectionTest {public static void main(String[] args) {// Create client configurationGlideClientConfiguration config = GlideClientConfiguration.builder().address(NodeAddress.builder().host("localhost").port(6379).build()).build();try (GlideClient client = GlideClient.createClient(config).get()) {// Test the connectionString response = client.ping().get();// Valkey respond with PONGSystem.out.println("Connected! Server responded: " + response);} catch (Exception e) {System.err.println("Connection failed: " + e.getMessage());}}}const { GlideClient } = require('@valkey/valkey-glide');async function main() {// Create client configurationconst client = GlideClient.createClient({addresses: [{ host: 'localhost', port: 6379 }]});try {// Test the connectionconst response = await client.ping();// Valkey respond with PONGconsole.log(`Connected! Server responded: ${response}`);} catch (error) {console.error(`Connection failed: ${error.message}`);} finally {// Always close the clientclient.close();}}// Run the functionmain().catch(console.error);package mainimport ("fmt""log""github.com/valkey-io/valkey-glide/go/glide/api")func main() {// Create client configurationconfig := &api.GlideClientConfiguration{Addresses: []api.NodeAddress{{Host: "localhost", Port: 6379},},}client := api.NewGlideClient(config)defer client.Close()// Test the connectionresponse, err := client.Ping()if err != nil {log.Fatalf("Connection failed: %v", err)}// Valkey respond with PONGfmt.Printf("Connected! Server responded: %s\n", response)} -
Running the above snippet should give you this respond.
Terminal window Connected! Server responded: PONG
Connection Configuration
Section titled “Connection Configuration”GLIDE offers many configuration options. A typical configuration may look like following:
import asynciofrom glide import GlideClient, NodeAddress, GlideClientConfiguration
async def main(): # Setting up connection configuration config = GlideClientConfiguration( addresses=[NodeAddress("localhost", 6379)], # Connection timeout (milliseconds) request_timeout=5000, # Connection pool size connection_backoff_max_delay=1000, # TLS configuration (if needed) use_tls=False, # Database selection (0-15 for Redis/Valkey) database_id=0 )
client = GlideClient(config)
try: # Test connection with custom message response = await client.ping("Hello GLIDE!") print(f"Server responded: {response}")
finally: await client.close()
if __name__ == "__main__": asyncio.run(main())import glide.api.GlideClient;import glide.api.models.configuration.GlideClientConfiguration;import glide.api.models.configuration.NodeAddress;import java.time.Duration;
public class AdvancedConnection { public static void main(String[] args) { // Setting up connection configuration GlideClientConfiguration config = GlideClientConfiguration.builder() .address(NodeAddress.builder() .host("localhost") .port(6379) .build()) // Connection timeout .requestTimeout(Duration.ofSeconds(5)) // TLS configuration (if needed) .useTls(false) // Database selection .databaseId(0) .build();
try (GlideClient client = GlideClient.createClient(config).get()) { // Test connection with custom message String response = client.ping("Hello GLIDE!").get(); System.out.println("Server responded: " + response);
} catch (Exception e) { System.err.println("Connection failed: " + e.getMessage()); } }}const { GlideClient } = require('@valkey/valkey-glide');
async function main() { // Setting up connection configuration const configs = { addresses: [{ host: 'localhost', port: 6379 }], // Connection timeout (milliseconds) requestTimeout: 5000, // TLS configuration (if needed) useTls: false, // Database selection (0-15 for Redis/Valkey) databaseId: 0 }
const client = GlideClient.createClient(configs);
try { // Test connection with custom message const response = await client.ping('Hello GLIDE!'); console.log(`Server responded: ${response}`);
} finally { client.close(); }}
main().catch(console.error);package main
import ( "fmt" "log" "time"
"github.com/valkey-io/valkey-glide/go/glide/api")
func main() { // Setting up connection configuration config := &api.GlideClientConfiguration{ Addresses: []api.NodeAddress{ {Host: "localhost", Port: 6379}, }, // Connection timeout RequestTimeout: 5 * time.Second, // TLS configuration (if needed) UseTls: false, // Database selection DatabaseId: 0, }
client := api.NewGlideClient(config) defer client.Close()
// Test connection with custom message response, err := client.PingWithMessage("Hello GLIDE!") if err != nil { log.Fatalf("Connection failed: %v", err) }
fmt.Printf("Server responded: %s\n", response)}Next Steps
Section titled “Next Steps”Congratulations, you are now connected to Valkey using GLIDE! To see how to make basic operations take a look at the our guide.