Giter Club home page Giter Club logo

nredisstack's Introduction

license .github/workflows/integration.yml pre-release 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, 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

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;
...
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");

Now you can create a variable from any type of module in the following way:

IBloomCommands bf = db.BF();
ICuckooCommands cf = db.CF();
ICmsCommands cms = db.CMS();
IGraphCommands graph = db.GRAPH();
ITopKCommands topk = db.TOPK();
ITdigestCommands tdigest = db.TDIGEST();
ISearchCommands ft = db.FT();
IJsonCommands json = db.JSON();
ITimeSeriesCommands ts = db.TS();

Then, that variable will allow you to call all the commands of that module.

Examples

Set JSON object to Redis

Set a json object to Redis:

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();

IJsonCommands json = db.JSON();
var key = "myKey";
json.Set(key, "$", new Person() { Age = 35, Name = "Alice" });

Index and search

We will see an example that shows how you can create an index, add a document to it and search it using NRedisStack.

Setup:

using NRedisStack;
...
IDatabase db = redisFixture.Redis.GetDatabase();
ISearchCommands ft = db.FT();
IJsonCommands 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 you create the index, any new hash documents with the doc: prefix are automatically indexed upon creation.

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

Author

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


Redis

nredisstack's People

Contributors

aviavni avatar chayim avatar shacharpash avatar slorello89 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.