Skip to content

Commit 7504d71

Browse files
uglideshacharPash
andauthored
Fix code examples in README (#86)
* Fix code examples in README - Specify all required dependencies - Add missing db initialization line - Use anonymous type to make JSON example runnable * Use consistent style for examples in README * Fix FT.CREATE example --------- Co-authored-by: shacharPash <[email protected]>
1 parent 19a3f1f commit 7504d71

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ This launches [Redis Stack](https://redis.io/docs/stack/), an extension of Redis
4949
Now, you need to connect to Redis, exactly the same way you do it in [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis):
5050
```csharp
5151
using NRedisStack;
52-
...
52+
using NRedisStack.RedisStackCommands;
53+
using StackExchange.Redis;
54+
//...
5355
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
56+
IDatabase db = redis.GetDatabase();
5457
```
5558
Now you can create a variable from any type of module in the following way:
5659
```csharp
@@ -78,7 +81,7 @@ IDatabase db = redis.GetDatabase();
7881

7982
IJsonCommands json = db.JSON();
8083
var key = "myKey";
81-
json.Set(key, "$", new Person() { Age = 35, Name = "Alice" });
84+
json.Set(key, "$", new { Age = 35, Name = "Alice" });
8285
```
8386

8487
### Index and search
@@ -87,17 +90,20 @@ Now, to execute a search for objects, we need to index them on the server, and
8790
Setup:
8891

8992
```csharp
90-
using NRedisStack;
91-
...
92-
IDatabase db = redisFixture.Redis.GetDatabase();
93+
using NRedisStack.Search;
94+
using NRedisStack.Search.Literals.Enums;
95+
//...
96+
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
97+
IDatabase db = redis.GetDatabase();
98+
9399
ISearchCommands ft = db.FT();
94100
IJsonCommands json = db.JSON();
95101
```
96102

97103
Create an index with fields and weights:
98104
```csharp
99105
// FT.CREATE myIdx ON HASH PREFIX 1 doc: SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXT
100-
ft.Create("myIndex", new FTCreateParams().On(IndexDataType.Hash)
106+
ft.Create("myIndex", new FTCreateParams().On(IndexDataType.HASH)
101107
.Prefix("doc:"),
102108
new Schema().AddTextField("title", 5.0)
103109
.AddTextField("body")

0 commit comments

Comments
 (0)