{
  "schema_version": 2,
  "id": "develop/clients/dotnet",
  "title": "StackExchange.Redis guide (C#/.NET)",
  "url": "https://redis.io/docs/latest/develop/clients/dotnet/",
  "summary": "Connect your .NET application to a Redis database",
  "aliases": [
    "/develop/connect/clients/dotnet",
    "/connect/clients/dotnet/",
    "/clients/dotnet/",
    "/develop/clients/stackexchange.redis"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-08T15:21:05+01:00",
  "children": [
    {
      "id": "develop/clients/dotnet/connect",
      "summary": "Connect your .NET application to a Redis database",
      "title": "Connect to the server",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/connect/"
    },
    {
      "id": "develop/clients/dotnet/nredisstack",
      "summary": "Access Redis Open Source modules",
      "title": "NRedisStack extensions guide",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/nredisstack/"
    },
    {
      "id": "develop/clients/dotnet/vecsets",
      "summary": "Index and query embeddings with Redis vector sets",
      "title": "Vector set embeddings",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/vecsets/"
    },
    {
      "id": "develop/clients/dotnet/transpipe",
      "summary": "Learn how to use Redis pipelines and transactions",
      "title": "Pipelines and transactions",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/transpipe/"
    },
    {
      "id": "develop/clients/dotnet/failover",
      "summary": "Improve reliability using the failover features of StackExchange.Redis.",
      "title": "Client-side geographic failover",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/failover/"
    },
    {
      "id": "develop/clients/dotnet/condexec",
      "summary": "Understand how `StackExchange.Redis` uses conditional execution.",
      "title": "Conditional execution",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/condexec/"
    },
    {
      "id": "develop/clients/dotnet/error-handling",
      "summary": "Learn how to handle errors when using StackExchange.Redis.",
      "title": "Error handling",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/error-handling/"
    },
    {
      "id": "develop/clients/dotnet/produsage",
      "summary": "Get your `StackExchange.Redis` app ready for production",
      "title": "Production usage",
      "url": "https://redis.io/docs/latest/develop/clients/dotnet/produsage/"
    }
  ],
  "page_type": "content",
  "content_hash": "272c6201292a4f50533ddf2d206e6fbf18bd1745fd0745c90f3648e4c034c03d",
  "sections": [
    {
      "id": "install",
      "title": "Install",
      "role": "setup",
      "text": "Using the `dotnet` CLI, run:\n\n[code example]"
    },
    {
      "id": "connect-and-test",
      "title": "Connect and test",
      "role": "content",
      "text": "Add the following imports to your source file:\n\nFoundational: Import required SE.Redis namespaces for Redis client functionality\n\n**Difficulty:** Beginner\n\n**Available in:** C#, C#\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n\n\nConnect to localhost on port 6379. The client supports both synchronous and asynchronous commands.\n\nFoundational: Connect to a Redis server and establish a client connection\n\n**Difficulty:** Beginner\n\n**Available in:** C#, C#\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n\n\nYou can test the connection by storing and retrieving a simple string.\n\nFoundational: Set and retrieve string values using SET and GET commands\n\n**Difficulty:** Beginner\n\n**Available in:** C#, C#\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n\n\nStore and retrieve a HashMap.\n\nFoundational: Store and retrieve hash data structures using HSET and HGETALL\n\n**Difficulty:** Beginner\n\n**Available in:** C#, C#\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]"
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "See the other pages in this section for more information and examples."
    }
  ],
  "examples": [
    {
      "id": "install-ex0",
      "language": "bash",
      "code": "dotnet add package StackExchange.Redis",
      "section_id": "install"
    },
    {
      "id": "connect-and-test-ex0",
      "language": "csharp",
      "code": "using StackExchange.Redis;",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex1",
      "language": "csharp",
      "code": "using StackExchange.Redis;",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex2",
      "language": "csharp",
      "code": "using StackExchange.Redis;",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex3",
      "language": "csharp",
      "code": "using StackExchange.Redis;",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex4",
      "language": "csharp",
      "code": "var muxer = await ConnectionMultiplexer.ConnectAsync(\"localhost:6379\");\n        var db = muxer.GetDatabase();",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex5",
      "language": "csharp",
      "code": "var muxer = ConnectionMultiplexer.Connect(\"localhost:6379\");\n        var db = muxer.GetDatabase();",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex6",
      "language": "csharp",
      "code": "var muxer = await ConnectionMultiplexer.ConnectAsync(\"localhost:6379\");\n        var db = muxer.GetDatabase();",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex7",
      "language": "csharp",
      "code": "var muxer = ConnectionMultiplexer.Connect(\"localhost:6379\");\n        var db = muxer.GetDatabase();",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex8",
      "language": "csharp",
      "code": "await db.StringSetAsync(\"foo\", \"bar\");\n        string? fooResult = await db.StringGetAsync(\"foo\");\n        Console.WriteLine(fooResult); // >>> bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex9",
      "language": "csharp",
      "code": "db.StringSet(\"foo\", \"bar\");\n        Console.WriteLine(db.StringGet(\"foo\")); // >>> bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex10",
      "language": "csharp",
      "code": "await db.StringSetAsync(\"foo\", \"bar\");\n        string? fooResult = await db.StringGetAsync(\"foo\");\n        Console.WriteLine(fooResult); // >>> bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex11",
      "language": "csharp",
      "code": "db.StringSet(\"foo\", \"bar\");\n        Console.WriteLine(db.StringGet(\"foo\")); // >>> bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex12",
      "language": "csharp",
      "code": "var hash = new HashEntry[] { \n            new HashEntry(\"name\", \"John\"), \n            new HashEntry(\"surname\", \"Smith\"),\n            new HashEntry(\"company\", \"Redis\"),\n            new HashEntry(\"age\", \"29\"),\n            };\n        await db.HashSetAsync(\"user-session:123\", hash);\n\n        var hashFields = await db.HashGetAllAsync(\"user-session:123\");\n        Console.WriteLine(String.Join(\"; \", hashFields));\n        // >>> name: John; surname: Smith; company: Redis; age: 29",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex13",
      "language": "csharp",
      "code": "var hash = new HashEntry[] {\n            new HashEntry(\"name\", \"John\"),\n            new HashEntry(\"surname\", \"Smith\"),\n            new HashEntry(\"company\", \"Redis\"),\n            new HashEntry(\"age\", \"29\"),\n        };\n        db.HashSet(\"user-session:123\", hash);\n\n        var hashFields = db.HashGetAll(\"user-session:123\");\n        Console.WriteLine(String.Join(\"; \", hashFields));\n        // >>> name: John; surname: Smith; company: Redis; age: 29",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex14",
      "language": "csharp",
      "code": "var hash = new HashEntry[] { \n            new HashEntry(\"name\", \"John\"), \n            new HashEntry(\"surname\", \"Smith\"),\n            new HashEntry(\"company\", \"Redis\"),\n            new HashEntry(\"age\", \"29\"),\n            };\n        await db.HashSetAsync(\"user-session:123\", hash);\n\n        var hashFields = await db.HashGetAllAsync(\"user-session:123\");\n        Console.WriteLine(String.Join(\"; \", hashFields));\n        // >>> name: John; surname: Smith; company: Redis; age: 29",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex15",
      "language": "csharp",
      "code": "var hash = new HashEntry[] {\n            new HashEntry(\"name\", \"John\"),\n            new HashEntry(\"surname\", \"Smith\"),\n            new HashEntry(\"company\", \"Redis\"),\n            new HashEntry(\"age\", \"29\"),\n        };\n        db.HashSet(\"user-session:123\", hash);\n\n        var hashFields = db.HashGetAll(\"user-session:123\");\n        Console.WriteLine(String.Join(\"; \", hashFields));\n        // >>> name: John; surname: Smith; company: Redis; age: 29",
      "section_id": "connect-and-test"
    }
  ]
}
