Skip to content

Commit 2ff8fce

Browse files
authored
Editing and writing a README file (#43)
* Changing 'Modules' to 'Stack' * Adding installation & getting started guide * Update Docker * Add redis logo image * Add Search Example * Fixes after review * Add words to wordlist
1 parent 1aa77cd commit 2ff8fce

File tree

3 files changed

+73
-8
lines changed

3 files changed

+73
-8
lines changed

.github/wordlist.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ OSS
88
Json
99
json
1010
TimeSeries
11-
NuGet
11+
NuGet
12+
cli
13+
dotnet
14+
HSET

README.md

+69-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Note
1111

12-
This project builds on [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis), and seeks to bring native support for Redis Modules to the C# ecosystem.
12+
This project builds on [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis), and seeks to bring native support for Redis Stack commands to the C# ecosystem.
1313

1414
## API
1515

@@ -18,15 +18,35 @@ The complete documentation for Redis module commands can be found at the [Redis
1818
### Redis OSS commands
1919
You can use Redis OSS commands in the same way as you use them in [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis).
2020

21-
### Modules Commands
21+
### Stack commands
2222
Each module has a command class with its own commands.
23-
The supported modules are: [Search](https://redis.io/commands/?group=search), [Json](https://redis.io/commands/?group=json), [Graph](https://redis.io/commands/?group=graph), [TimeSeries](https://redis.io/commands/?group=timeseries), [Bloom Filter](https://redis.io/commands/?group=bf), [Cuckoo Filter](https://redis.io/commands/?group=cf), [T-Digest](https://redis.io/commands/?group=tdigest), [Count-min Sketch](https://redis.io/commands/?group=cms) and [Top-K](https://redis.io/commands/?group=topk).
23+
The supported modules are [Search](https://redis.io/commands/?group=search), [JSON](https://redis.io/commands/?group=json), [Graph](https://redis.io/commands/?group=graph), [TimeSeries](https://redis.io/commands/?group=timeseries), [Bloom Filter](https://redis.io/commands/?group=bf), [Cuckoo Filter](https://redis.io/commands/?group=cf), [T-Digest](https://redis.io/commands/?group=tdigest), [Count-min Sketch](https://redis.io/commands/?group=cms), and [Top-K](https://redis.io/commands/?group=topk).
2424

2525
# Usage
2626

27-
First, you need to connect to Redis, exactly the same way you do it in [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis):
27+
## 💻 Installation
28+
29+
Using the dotnet cli, run:
30+
31+
```text
32+
dotnet add package NRedisStack
33+
```
34+
35+
## 🏁 Getting started
36+
37+
### Starting Redis
38+
39+
Before writing any code, you'll need a Redis instance with the appropriate Redis modules. The quickest way to get this is with Docker:
40+
41+
```sh
42+
docker run -p 6379:6379 --name redis-stack redis/redis-stack:latest
43+
```
44+
45+
This launches [Redis Stack](https://redis.io/docs/stack/), an extension of Redis that adds modern data structures to Redis.
46+
47+
Now, you need to connect to Redis, exactly the same way you do it in [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis):
2848
```csharp
29-
using StackExchange.Redis;
49+
using NRedisStack;
3050
...
3151
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
3252
```
@@ -43,7 +63,8 @@ IJsonCommands json = db.JSON();
4363
ITimeSeriesCommands ts = db.TS();
4464
```
4565
Then, that variable will allow you to call all the commands of that module.
46-
## Basic Example
66+
## Examples
67+
### Set JSON object to Redis
4768
Set a json object to Redis:
4869
```csharp
4970
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
@@ -53,13 +74,54 @@ IJsonCommands json = db.JSON();
5374
var key = "myKey";
5475
json.Set(key, "$", new Person() { Age = 35, Name = "Alice" });
5576
```
77+
### Index and search
78+
We will see an example that shows how you can create an index, add a document to it and search it using NRedisStack.
79+
80+
Setup:
81+
```csharp
82+
using NRedisStack;
83+
...
84+
IDatabase db = redisFixture.Redis.GetDatabase();
85+
ISearchCommands ft = db.FT();
86+
IJsonCommands json = db.JSON();
87+
```
88+
Create an index with fields and weights:
89+
```csharp
90+
// FT.CREATE myIdx ON HASH PREFIX 1 doc: SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXT
91+
ft.Create("myIndex", new FTCreateParams().On(IndexDataType.Hash)
92+
.Prefix("doc:"),
93+
new Schema().AddTextField("title", 5.0)
94+
.AddTextField("body")
95+
.AddTextField("url"));
96+
```
97+
98+
After you create the index, any new hash documents with the doc: prefix are automatically indexed upon creation.
99+
56100

101+
To create a new hash document and add it to the index, use the HSET command:
102+
```csharp
103+
// HSET doc:1 title "hello world" body "lorem ipsum" url "http://redis.io"
104+
db.HashSet("doc:1", new HashEntry[] { new("title", "hello world"),
105+
new("body", "lorem ipsum"),
106+
new("url", "http://redis.io") });
107+
```
108+
Search the index for documents that contain "hello world":
109+
```csharp
110+
// FT.SEARCH myIndex "hello world" LIMIT 0 10
111+
ft.Search("myIndex", new Query("hello world").Limit(0, 10));
112+
```
113+
Drop the index:
114+
```csharp
115+
// FT.DROPINDEX myIndex
116+
ft.DropIndex("myIndex");
117+
```
57118
------
58119

59120
### Author
60121

61122
NRedisStack is developed and maintained by [Redis Inc](https://redis.com). It can be found [here](
62123
https://github.com/redis/NRedisStack), or downloaded from [NuGet](https://www.nuget.org/packages/NRedisStack).
63124

64-
[![Redis](./docs/logo-redis.png)](https://www.redis.com)
125+
---
65126

127+
[![Redis](./docs/logo-redis.png)](https://www.redis.com)

docs/logo-redis.png

8.19 KB
Loading

0 commit comments

Comments
 (0)