General Language Independent Driver for the Enterprise (GLIDE) for Valkey
$ dotnet add package Valkey.GlideValkey General Language Independent Driver for the Enterprise (GLIDE) is the official open-source Valkey client library for C#. Built on a robust Rust core, it provides high-performance, reliable connectivity to Valkey and Redis OSS servers with comprehensive async/await support.
[!IMPORTANT] Valkey.Glide C# wrapper is in a preview state and still has many features that remain to be implemented before GA.
Valkey GLIDE for C# is API-compatible with the following engine versions:
| Engine Type | 6.2 | 7.0 | 7.1 | 7.2 | 8.0 | 8.1 |
|---|---|---|---|---|---|---|
| Valkey | - | - | - | V | V | V |
| Redis | V | V | V | V | - | - |
Install the Valkey GLIDE package from NuGet:
dotnet add package Valkey.Glide
Or via Package Manager Console in Visual Studio:
Install-Package Valkey.Glide
using Valkey.Glide;
// Create a standalone client
var connection = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
var db = connection.Database;
// Basic string operations
await db.StringSetAsync("key", "value");
var result = await db.StringGetAsync("key");
Console.WriteLine($"Retrieved: {result}");
using Valkey.Glide;
using static Valkey.Glide.ConnectionConfiguration;
// Create a cluster client
var config = new ClusterClientConfigurationBuilder()
.WithAddress("cluster-node1.example.com", 6379)
.WithAddress("cluster-node2.example.com", 6379)
.WithAddress("cluster-node3.example.com", 6379)
.Build();
using var client = await GlideClusterClient.CreateClient(config);
// Cluster operations work seamlessly
await client.StringSetAsync("user:1000", "John Doe");
var user = await client.StringGetAsync("user:1000");
Console.WriteLine($"User: {user}");
var config = new StandaloneClientConfigurationBuilder()
.WithAddress("secure-server.example.com", 6380)
.WithAuthentication("username", "password")
.WithTls()
.Build();
using var client = await GlideClient.CreateClient(config);
// Set and get strings
await client.StringSetAsync("greeting", "Hello, World!");
var greeting = await client.StringGetAsync("greeting");
// Multiple keys
var keyValuePairs = new KeyValuePair<ValkeyKey, ValkeyValue>[]
{
new("key1", "value1"),
new("key2", "value2")
};
await client.StringSetAsync(keyValuePairs);
var values = await client.StringGetAsync(new[] { "key1", "key2" });
// Hash operations
await client.HashSetAsync("user:1000", "name", "John Doe");
await client.HashSetAsync("user:1000", "email", "john@example.com");
var name = await client.HashGetAsync("user:1000", "name");
var allFields = await client.HashGetAllAsync("user:1000");
// List operations
await client.ListPushAsync("tasks", "task1", ListDirection.Left);
await client.ListPushAsync("tasks", "task2", ListDirection.Left);
var task = await client.ListPopAsync("tasks", ListDirection.Right);
var allTasks = await client.ListRangeAsync("tasks", 0, -1);
// Set operations
await client.SetAddAsync("tags", "csharp");
await client.SetAddAsync("tags", "dotnet");
await client.SetAddAsync("tags", "valkey");
var isMember = await client.SetIsMemberAsync("tags", "csharp");
var allTags = await client.SetMembersAsync("tags");
Development instructions for local building & testing the package are in the DEVELOPER.md file.
Valkey GLIDE for C# is built for high performance:
try
{
await client.StringSetAsync("key", "value");
var result = await client.StringGetAsync("key");
}
catch (ConnectionException ex)
{
Console.WriteLine($"Connection error: {ex.Message}");
}
catch (TimeoutException ex)
{
Console.WriteLine($"Operation timed out: {ex.Message}");
}
catch (ValkeyException ex)
{
Console.WriteLine($"Valkey error: {ex.Message}");
}
We welcome contributions! Please see our Contributing Guidelines for details on:
When reporting issues, please include:
This project is licensed under the Apache License 2.0.
Valkey GLIDE for C# integrates well with the .NET ecosystem:
Ready to get started? Install the NuGet package and check out our Quick Start guide!