百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

NRedisStack

> 编程语言
开源

Redis Stack .Net 客户端

326 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Redis Stack .Net 客户端

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.

How do I Redis?

Learn for free at Redis University

Try the Redis Cloud

Dive in developer tutorials

Join the Redis community

Work at Redis

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, TimeSeries, Bloom Filter, Cuckoo Filter, T-Digest, Count-min Sketch, and Top-K.

Note: RedisGraph support has been deprecated starting from Redis Stack version 7.2. For more information, please refer to this blog post.

IMPORTANT: NRedisStack will end the support for Graph functionalities with version 0.13.x

IMPORTANT: Starting from version 1.0.0-beta1, by default, the client now overrides the server-side dialect with version 2, automatically appending DIALECT 2 to commands like FT.AGGREGATE and FT.SEARCH. Be aware that the query dialect may impact the results returned. If needed, you can revert to a different dialect version by configuring the client accordingly. Please see release notes.

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 7.2, 7.4, 8.0 and 8.2.

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:

bash
docker run -p 6379:6379 --name redis redis:latest

Now, you need to connect to Redis, exactly the same way you do it in StackExchange.Redis:

csharp
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:

csharp
BloomCommands bf = db.BF();
CuckooCommands cf = db.CF();
CmsCommands cms = db.CMS();
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:

csharp
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:

csharp
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:

csharp
// 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:

csharp
// 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":

csharp
// FT.SEARCH myIndex "hello world" LIMIT 0 10
ft.Search("myIndex", new Query("hello world").Limit(0, 10));

Drop the index:

csharp
// FT.DROPINDEX myIndex
ft.DropIndex("myIndex");

More examples can be found in the examples folder.

For Contributors

To contribute NRedisStack, please see :point_right: Contribution notes


Author

NRedisStack is developed and maintained by Redis Inc. It can be found here, or downloaded from NuGet.


Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言