{"id":15011619,"url":"https://github.com/melittleman/rediskit","last_synced_at":"2026-02-19T00:03:29.954Z","repository":{"id":211958193,"uuid":"730367134","full_name":"melittleman/RedisKit","owner":"melittleman","description":"A .NET 8 helper library for common Redis client functionality.","archived":false,"fork":false,"pushed_at":"2024-02-26T09:36:33.000Z","size":153,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T02:41:25.360Z","etag":null,"topics":["dotnet","nuget","nuget-package","redis","redis-client","redis-json","redis-search","redis-stack"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/melittleman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-11T19:12:08.000Z","updated_at":"2024-02-13T12:19:40.000Z","dependencies_parsed_at":"2024-02-06T10:28:34.199Z","dependency_job_id":"3370a9e0-23f8-4d17-9ae4-05d3fb3e33c5","html_url":"https://github.com/melittleman/RedisKit","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"460a5047481da9ba7c907a4be1c17cb8d73e59ae"},"previous_names":["melittleman/nrediskit"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/melittleman/RedisKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melittleman%2FRedisKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melittleman%2FRedisKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melittleman%2FRedisKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melittleman%2FRedisKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/melittleman","download_url":"https://codeload.github.com/melittleman/RedisKit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melittleman%2FRedisKit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019343,"owners_count":26086711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","nuget","nuget-package","redis","redis-client","redis-json","redis-search","redis-stack"],"created_at":"2024-09-24T19:41:21.179Z","updated_at":"2025-10-14T15:41:54.906Z","avatar_url":"https://github.com/melittleman.png","language":"C#","readme":"# RedisKit\n\u003e A .NET 8 helper library for common Redis client functionality.\n\nThis package aims to build upon [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis) and [NRedisStack](https://github.com/redis/NRedisStack) in order to provide all the functionality needed to get up and running with a new project utilizing Redis as fast as possible. \n\nWith **RedisKit** you can add multiple named Redis connections within the Dependency Injection container _(beneficial in hybrid environments where Redis server setups could be different e.g. persistent vs non-persistent)_, then configure each of these connections with features such as .NET Data Protection keys persistence, an `ITicketStore` implementation to store large Claims Principals from your application's authentication cookies _(very useful within Blazor Server applications where no HTTP Context is available)_, individual health checks to each Redis server, message consumer and producer implementations to make working with Redis Streams more simple as well as many other helpful methods and extensions for working with the [RedisJSON](https://redis.io/docs/data-types/json) and [RediSearch](https://github.com/RediSearch/RediSearch) modules.\n\n[![Build \u0026 Test](https://github.com/melittleman/RedisKit/actions/workflows/build-test.yml/badge.svg)](https://github.com/melittleman/RedisKit/actions/workflows/build-test.yml)\n\n## Contents\n- [Getting Started](#getting-started)\n- [Repository Structure](#repository-structure)\n- [Usage](#usage)\n    * [Adding A Named Connection](#adding-a-named-connection)\n    * [Using A Named Connection](#using-a-named-connection)\n    * [Add Multiple Connections](#add-multiple-connections)\n    * [Building A Connection](#building-a-connection)\n        - [JSON Documents](#json-documents)\n        - [Messaging](#Messaging)\n        - [Data Protection](#data-protection)\n        - [Authentication](#authentication)\n        - [Health Checks](#health-checks)\n\n## Getting Started\nTo get started with this library, you will first need to download and install either the [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) or Microsoft [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) which comes bundled with the SDK.\n\n## Repository Structure\n- **.github** - Files needed by GitHub are contained in the `.github` directory. For example; the `workflows` directory contains any _Build_, _Test_ or _Package_ configurations needed by **GitHub** [**Actions**](https://github.com/melittleman/RedisKit/actions).\n- **src** - The _Source_ directory contains all the source code for the library.\n- **test** - Contains all unit and integration tests relating to the **src** directory. These tests are implemented in [XUnit](https://xunit.net/) and can be run using the ```dotnet test``` CLI. These tests will also be run as part of the [Build \u0026 Test](https://github.com/melittleman/RedisKit/actions/workflows/build-test.yml) workflow in GitHub Actions.\n\n## Usage\nOnce you have installed the desired version of **RedisKit** you can configure this during service registration to be used by an application in the following ways.\n\n### Adding A Named Connection\nYou can add a named Redis connection to the Dependency Injection container and configure it by passing in an `Action` of `RedisConnectionOptions`.\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices.AddRedisConnection(\"cloud-cache\", options =\u003e\n{\n    options.ClientName = \"MyCompany.MyProduct\";\n    options.ConnectionString = \"redislabs.com:6379,allowAdmin=true,ssl=false\";\n});\n```\n\nThe `ConnectionString` property can be provided in either of two ways:\n1. Using the `StackExchange.Redis` format with a comma-separated list of arguments as outlined [here](https://stackexchange.github.io/StackExchange.Redis/Configuration.html#basic-configuration-strings). \nFor example: `redis0:6379,redis1:6380,allowAdmin=true,ssl=false`\n2. Using the Redis CLI URI style with the `redis://` protocol prefix. For example: `redis://username:password@redislabs.com:1234`\n\n### Using A Named Connection\n\nThis can then be used later anywhere in the application via the Singleton `IRedisConnectionProvider` that retrieves named Redis connections.\n```csharp\nusing RedisKit;\nusing RedisKit.DependencyInjection.Abstractions;\n\nprivate readonly IRedisConnection _redis;\n\npublic MyClassConstructor(IRedisConnectionProvider provider)\n{\n    _redis = provider.GetRequiredConnection(\"cloud-cache\");\n}\n\npublic async Task DoSomethingAsync()\n{\n    await _redis.Db.StringSetAsync(\"key\", \"value\");\n}\n```\n\nIf only a single Redis connection is being used within the application, this can then easily be retrieved directly from DI, rather than going via the provider.\n```csharp\nusing RedisKit.Abstractions;\n\nprivate readonly IRedisConnection _redis;\n\npublic MyClassConstructor(IRedisConnection redis)\n{\n    _redis = redis\n}\n\npublic Task\u003cT\u003e GetSomethingAsync()\n{\n    return _redis.Db.HashGetAsync\u003cT\u003e(\"key\");\n}\n```\n\nYou can continue to use a connection in exactly the same ways that you would otherwise use [NRedisStack](https://github.com/redis/NRedisStack) or [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis) directly.\n```csharp\nusing StackExchange.Redis;\n\nusing NRedisStack;\nusing NRedisStack.RedisStackCommands;\n\nusing RedisKit.DependencyInjection.Abstractions;\n\nprivate readonly IRedisConnection _redis;\n\npublic MyClassConstructor(IRedisConnectionProvider provider)\n{\n    _redis = provider.GetRequiredConnection(\"enterprise-db\");\n}\n\npublic async Task\u003cbool\u003e ExpireKeyAsync()\n{\n    IDatabase db = _redis.Db;\n\n    return await db.KeyExpireAsync(\"key\", TimeSpan.FromMinutes(5));\n}\n\npublic async Task\u003cdouble\u003e IncrementNumberAsync() \n{\n    JsonCommands json = _redis.Json;\n\n    return await json.NumberIncrbyAsync(\"key\", \"$.number\", 1.2);\n}\n```\n\n### Add Multiple Connections\nThe main benefit of configuring these named connections is to be able to connect to multiple Redis servers from a single application when the requirements of that connection differ.\nFor example; a caching instance that does not have persistence or high availability enabled, and therefore reduces costs. And a Messaging instance, where both persistence and AOF writing may be needed.\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices.AddRedisConnection(\"enterprise-cache\", options =\u003e\n{\n    options.ClientName = \"MyCompany.MyApplication.Caching\";\n    options.ConnectionString = \"redislabs.com:18526,allowAdmin=false,ssl=true\";\n});\n\nservices.AddRedisConnection(\"onprem-message-broker\", options =\u003e\n{\n    options.ClientName = \"MyProduct.Messaging\";\n    options.ConnectionString = \"redis://username:password@localhost:6379\";\n});\n```\n\nThese can then individually both be retrieved and used in the same way as detailed above in the [Using A Named Connection](#using-a-named-connection) section.\n\n### Building A Connection\nThe return type of `IServiceCollection.AddRedisConnection()` is a new instance of `IRedisConnectionBuilder` which can be used to chain further configuration onto this connection via it's _Fluent_ API.\nFor example, to add the .NET Data Protection middleware to the application that utilizes your named Redis connection:\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices\n    .AddRedisConnection(\"elasticache\", options...)\n    .AddRedisDataProtection();\n```\n\n#### JSON Documents\n**RedisKit** is also able to help abstract Redis JSON document usage within the application. You can use your own custom JSON converters for (de)serialization by configuring it in the following way.\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices.ConfigureRedisJson(options =\u003e\n{\n    options.Serializer.Converters.Add(new MyCustomJsonConverter());\n});\n```\n\nThen pass the `RedisJsonOptions` into the available `JsonCommands` methods. \n```csharp\nusing RedisKit.DependencyInjection.Abstractions;\n\nprivate readonly JsonCommands _json;\nprivate readonly RedisJsonOptions _options;\n\npublic MyClassConstructor(IRedisConnectionProvider provider, IOptions\u003cRedisJsonOptions\u003e options)\n{\n    IRedisConnection redis = provider.GetRequiredConnection(\"document-db\");\n\n    _json = redis.Json;\n    _options = options.Value;\n}\n\npublic Task\u003cMyCustomClass\u003e GetSomethingAsync()\n{\n    return _json.GetAsync\u003cMyCustomClass\u003e(\"key\", _options);\n}\n```\n\n#### Messaging\nThere are `IMessageConsumer\u003cT\u003e` and `IMessageProducer\u003cT\u003e` abstractions available for interacting with Redis as a message broker. \nThis utilizes the **Redis Streams** data type on the server and is implemented in the `RedisStreamsConsumer\u003cTMessage\u003e` and `RedisStreamsProducer\u003cTMessage\u003e` services respectively.\n\nIn order to get started simply chain either one or both of the methods below during service registration.\n\u003e **Note**: These do not need to be chained to the same connection. For example you could _Consume_ messages from an internal Redis server and then _Produce_ these out to an entirely different public server.\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices\n    .AddRedisConnection(\"message-broker\", options...)\n    .AddRedisStreamsConsumer(options =\u003e\n    {\n        options.ConsumerGroupName = \"Project.ClientApp.Consumer\";\n\n    }).AddRedisStreamsProducer();\n```\n\nYou can then request these abstractions from the Dependency Injection container and use them to produce or consume messages.\n\n```csharp\nusing RedisKit.Messaging.Abstractions;\n\nprivate readonly IMessageConsumer\u003cMyMessage\u003e _consumer;\nprivate readonly IMessageProducer\u003cMyMessage\u003e _producer;\n\npublic MyMessagingClass(IMessageConsumer\u003cMyMessage\u003e consumer, IMessageProducer\u003cMyMessage\u003e producer)\n{\n    _consumer = consumer;\n    _producer = producer\n}\n\npublic Task ConsumeSomethingAsync()\n{\n    MessageResult\u003cICollection\u003cMyMessage\u003e\u003e results = await _consumer.ConsumeAsync(5);\n\n    // omitted for brevity\n}\n\npublic Task ProduceSomethingAsync(MyMessage message)\n{\n    bool success = await _producer.SendAsync(\"key\", message)\n\n    // omitted for brevity\n}\n```\n\n\u003e **Note**: Unfortunately there is a limitation in the `StackExchange.Redis` library that prevents blocking reads, due to the fact that all commands leverage a single `ConnectionMultiplexer` instance. \n\u003e Therefore, message consumers will need to periodically request messages as appropriate. See more informaion [here](https://developer.redis.com/develop/dotnet/streams/blocking-reads).\n\n#### Data Protection\nThe .NET Data Protection providers can be configured to use your named Redis connection and save the keys under a specified location like the following:\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices\n    .AddRedisConnection(\"redis-persistent\", options...)\n    .AddRedisDataProtection(options =\u003e\n    {\n        options.KeyName = \"my-application:data-protection:keys\";\n    });\n```\n\n#### Authentication\nIf using cookie authentication, there is a provided implementation of `ITicketStore` that can be configured on `CookieAuthenticationOptions` in order\nto utilize the named Redis connection to store instances of `AuthenticationTicket` within the server as JSON. This then easily allows for distributed\nauthentication sessions, and removes the reliance on browsers storing very large `ClaimsPrincipal` payloads and from purging this data when they are expected to.\n\n\u003e **Note**: You MUST ensure that [Data Protection](#data-protection) has been configured for this to work correctly.\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\nusing RedisKit.Json.Converters;\n\nservices\n    .AddRedisConnection(\"redis-persistent\", options...)\n    .AddRedisDataProtection(options...)\n    .AddRedisTicketStore(options =\u003e\n    {\n        options.KeyPrefix = \"client-app:authentication:tickets:\";\n        options.CookieSchemeName = \"My Cookie Scheme\";\n    });\n```\n\n#### Health Checks\nYou can configure the built in .NET Health Check framework to test connectivity to your named Redis connection as part of it's configured Health Checks.\n\n```csharp\nusing RedisKit.DependencyInjection.Extensions;\n\nservices\n    .AddRedisConnection(\"redis-server\", options...)\n    .AddHealthCheck();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelittleman%2Frediskit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelittleman%2Frediskit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelittleman%2Frediskit/lists"}