NRedisStack 0.8.1
See the version list below for details.
dotnet add package NRedisStack --version 0.8.1
NuGet\Install-Package NRedisStack -Version 0.8.1
<PackageReference Include="NRedisStack" Version="0.8.1" />
paket add NRedisStack --version 0.8.1
#r "nuget: NRedisStack, 0.8.1"
// Install NRedisStack as a Cake Addin #addin nuget:?package=NRedisStack&version=0.8.1 // Install NRedisStack as a Cake Tool #tool nuget:?package=NRedisStack&version=0.8.1
NRedisStack
.NET Client for Redis
Note
This project builds on StackExchange.Redis, and seeks to bring native support for Redis Stack commands to the C# ecosystem.
API
The complete documentation for Redis module commands can be found at the Redis commands website.
Redis OSS commands
You can use Redis OSS commands in the same way as you use them in StackExchange.Redis.
Stack commands
Each module has a command class with its own commands. The supported modules are Search, JSON, Graph, TimeSeries, Bloom Filter, Cuckoo Filter, T-Digest, Count-min Sketch, and Top-K.
Usage
💻 Installation
Using the dotnet cli, run:
dotnet add package NRedisStack
🏁 Getting started
Supported Redis versions
The most recent version of this library supports Redis version 6.2, 7.0.
Starting Redis
Before writing any code, you'll need a Redis instance with the appropriate Redis modules. The quickest way to get this is with Docker:
docker run -p 6379:6379 --name redis-stack redis/redis-stack:latest
This launches Redis Stack, an extension of Redis that adds modern data structures to Redis.
Now, you need to connect to Redis, exactly the same way you do it in StackExchange.Redis:
using NRedisStack;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
//...
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
Now you can create a variable from any type of module in the following way:
BloomCommands bf = db.BF();
CuckooCommands cf = db.CF();
CmsCommands cms = db.CMS();
GraphCommands graph = db.GRAPH();
TopKCommands topk = db.TOPK();
TdigestCommands tdigest = db.TDIGEST();
SearchCommands ft = db.FT();
JsonCommands json = db.JSON();
TimeSeriesCommands ts = db.TS();
Then, that variable will allow you to call all the commands of that module.
Examples
Store a JSON object in Redis
To store a json object in Redis:
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
JsonCommands json = db.JSON();
var key = "myKey";
json.Set(key, "$", new { Age = 35, Name = "Alice" });
Index and search
Now, to execute a search for objects, we need to index them on the server, and run a query:
Setup:
using NRedisStack.Search;
using NRedisStack.Search.Literals.Enums;
//...
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
SearchCommands ft = db.FT();
JsonCommands json = db.JSON();
Create an index with fields and weights:
// FT.CREATE myIdx ON HASH PREFIX 1 doc: SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXT
ft.Create("myIndex", new FTCreateParams().On(IndexDataType.HASH)
.Prefix("doc:"),
new Schema().AddTextField("title", 5.0)
.AddTextField("body")
.AddTextField("url"));
After creating the index, future documents with the doc:
prefix will be automatically indexed when created or modified.
To create a new hash document and add it to the index, use the HSET command:
// HSET doc:1 title "hello world" body "lorem ipsum" url "http://redis.io"
db.HashSet("doc:1", new HashEntry[] { new("title", "hello world"),
new("body", "lorem ipsum"),
new("url", "http://redis.io") });
Search the index for documents that contain "hello world":
// FT.SEARCH myIndex "hello world" LIMIT 0 10
ft.Search("myIndex", new Query("hello world").Limit(0, 10));
Drop the index:
// FT.DROPINDEX myIndex
ft.DropIndex("myIndex");
More examples can be found in the examples folder.
Author
NRedisStack is developed and maintained by Redis Inc. It can be found here, or downloaded from NuGet.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- StackExchange.Redis (>= 2.6.96)
- System.Text.Json (>= 7.0.2)
-
net6.0
- StackExchange.Redis (>= 2.6.96)
-
net7.0
- StackExchange.Redis (>= 2.6.96)
NuGet packages (26)
Showing the top 5 NuGet packages that depend on NRedisStack:
Package | Downloads |
---|---|
Microsoft.KernelMemory.MemoryDb.Redis
Redis connector for Microsoft Kernel Memory, to store and search memory using Redis vector search and other Redis features. |
|
Microsoft.SemanticKernel.Connectors.Redis
Redis connector for Semantic Kernel plugins and semantic memory |
|
ShayganTadbir.Framework.Core
Package description |
|
FCMicroservices
a boilerplate microservice framework |
|
Aardworx.PointShare.Import
Aardworx PointShare. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on NRedisStack:
Repository | Stars |
---|---|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
microsoft/kernel-memory
RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
|
|
redis/NRedisStack
Redis Stack .Net client
|
Version | Downloads | Last updated |
---|---|---|
0.13.1 | 16,842 | 11/22/2024 |
0.13.0 | 143,501 | 9/13/2024 |
0.12.0 | 861,923 | 3/12/2024 |
0.11.0 | 432,042 | 12/19/2023 |
0.10.1 | 136,489 | 10/22/2023 |
0.10.0 | 2,267 | 10/19/2023 |
0.9.0 | 244,306 | 9/3/2023 |
0.8.1 | 103,202 | 8/16/2023 |
0.8.0 | 669,050 | 7/5/2023 |
0.7.0 | 35,013 | 6/15/2023 |
0.6.1 | 73,274 | 5/3/2023 |
0.6.0 | 91,583 | 3/15/2023 |
0.5.1 | 10,612 | 2/8/2023 |
0.5.0 | 746 | 1/12/2023 |
0.4.1 | 585 | 11/30/2022 |
0.3.0 | 461 | 10/12/2022 |
0.2.2 | 448 | 10/2/2022 |
0.2.1 | 454 | 9/6/2022 |
0.1.0 | 1,906 | 8/17/2022 |