• Stars
    star
    220
  • Rank 180,422 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 2 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Redis Stack .Net client

license .github/workflows/integration.yml codecov NRedisStack NuGet release

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, 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.

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

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();
TopKCommands topk = db.TOPK();
TdigestCommands tdigest = db.TDIGEST();
SearchCommands ft = db.FT();
JsonCommands json = db.JSON();
TimeSeriesCommands ts = db.TS();
GraphCommands graph = db.GRAPH(); // If Redis version is less than 7.2

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" });

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.


Redis

More Repositories

1

redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.
C
66,875
star
2

go-redis

Redis Go client
Go
19,891
star
3

node-redis

Redis Node.js client
TypeScript
16,841
star
4

ioredis

๐Ÿš€ A robust, performance-focused, and full-featured Redis client for Node.js.
TypeScript
14,344
star
5

redis-py

Redis Python client
Python
12,506
star
6

jedis

Redis Java client
Java
11,766
star
7

hiredis

Minimalistic C client for Redis >= 1.2
C
6,197
star
8

lettuce

Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
Java
5,352
star
9

redis-rb

A Ruby client library for Redis
Ruby
3,963
star
10

rueidis

A fast Golang Redis client that supports Client Side Caching, Auto Pipelining, Generics OM, RedisJSON, RedisBloom, RediSearch, etc.
Go
2,327
star
11

redis-doc

Redis documentation source code for markdown and metadata files, conversion scripts, and so forth
Shell
2,310
star
12

redis-om-node

Object mapping, and more, for Redis and Node.js. Written in TypeScript.
TypeScript
1,158
star
13

docker-library-redis

Docker Official Image packaging for Redis
Shell
1,117
star
14

redis-om-python

Object mapping, and more, for Redis and Python
Python
1,093
star
15

redis-io

Application running http://redis.io
Ruby
637
star
16

redis-om-spring

Spring Data Redis extensions for better search, documents models, and more
Java
599
star
17

hiredis-py

Python wrapper for hiredis
C
495
star
18

redis-om-dotnet

Object mapping, and more, for Redis and .NET
C#
457
star
19

hiredis-rb

Ruby wrapper for hiredis
Ruby
319
star
20

hiredis-node

Node wrapper for hiredis
JavaScript
305
star
21

riot

๐Ÿงจ Get data in & out of Redis with RIOT
Java
273
star
22

redis-vl-python

Redis Vector Library (RedisVL) interfaces with Redis' vector database for realtime semantic search, RAG, and recommendation systems.
Python
218
star
23

redis-rcp

Redis Change Proposals
136
star
24

redis-hashes

Redis tarball SHA1 hashes
92
star
25

lettucemod

Java client for Redis Modules
Java
50
star
26

spring-batch-redis

Spring Batch extension for Redis
Java
47
star
27

redis-specifications

A bin for Redis' specs
38
star
28

minipilot

MiniPilot is a GenAI-assisted chatbot backed by Redis. Chat with your documents
HTML
31
star
29

redis-benchmarks-specification

The Redis benchmarks specification describes the cross-language/tools requirements and expectations to foster performance and observability standards around redis related technologies. Members from both industry and academia, including organizations and individuals are encouraged to contribute.
Python
29
star
30

librdb

Redis RDB file parser, with JSON, RESP and RDB-loader extensions
C
23
star
31

docs

Documentation for Redis, Redis Cloud, and Redis Enterprise
Python
23
star
32

redis-debian

Debian packaging
Shell
18
star
33

redis-snap

A repository for snap packaging
10
star
34

redis-website

HTML
9
star
35

Redis-Insight-Guides

Learn modern data models and data processing tools bundled in Redis Stack to build real-time applications with the speed and stability of Redis.
5
star
36

redis-clinterwebz

Python
4
star
37

redis-extra-ci

4
star
38

riot-docker

Dockerfile
2
star
39

redis-rpm

Shell
2
star
40

scoop

1
star
41

homebrew-tap

Homebrew tap for Redis organization
Ruby
1
star