Skip to content

Commit a922bdc

Browse files
authored
Merge branch 'master' into add-strong-name-signing
2 parents 25a8a0e + 519c9c2 commit a922bdc

File tree

2 files changed

+187
-10
lines changed

2 files changed

+187
-10
lines changed

tests/Doc/HomeJsonExample.cs

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ public void run()
8686
schema
8787
);
8888
// STEP_END
89-
90-
// Tests for 'make_index' step.
9189
// REMOVE_START
9290
Assert.True(indexCreated);
9391
// REMOVE_END
@@ -98,8 +96,6 @@ public void run()
9896
bool user2Set = db.JSON().Set("user:2", "$", user2);
9997
bool user3Set = db.JSON().Set("user:3", "$", user3);
10098
// STEP_END
101-
102-
// Tests for 'add_data' step.
10399
// REMOVE_START
104100
Assert.True(user1Set);
105101
Assert.True(user2Set);
@@ -118,8 +114,6 @@ public void run()
118114
));
119115
// >>> {"name":"Paul Zamir","email":"[email protected]", ...
120116
// STEP_END
121-
122-
// Tests for 'query1' step.
123117
// REMOVE_START
124118
Assert.Equal(
125119
"{\"name\":\"Paul Zamir\",\"email\":\"[email protected]\",\"age\":35,\"city\":\"Tel Aviv\"}",
@@ -140,8 +134,6 @@ public void run()
140134
));
141135
// >>> London, Tel Aviv
142136
// STEP_END
143-
144-
// Tests for 'query2' step.
145137
// REMOVE_START
146138
Assert.Equal(
147139
"London, Tel Aviv",
@@ -166,8 +158,6 @@ public void run()
166158
// >>> London - 1
167159
// >>> Tel Aviv - 2
168160
// STEP_END
169-
170-
// Tests for 'query3' step.
171161
// REMOVE_START
172162
Assert.Equal(2, resultsList.Count);
173163

@@ -181,7 +171,70 @@ public void run()
181171
Assert.Equal(2, testItem["count"]);
182172
// REMOVE_END
183173

174+
// STEP_START make_hash_index
175+
var hashSchema = new Schema()
176+
.AddTextField("name")
177+
.AddTagField("city")
178+
.AddNumericField("age");
179+
180+
bool hashIndexCreated = db.FT().Create(
181+
"hash-idx:users",
182+
new FTCreateParams()
183+
.On(IndexDataType.HASH)
184+
.Prefix("huser:"),
185+
hashSchema
186+
);
187+
// STEP_END
188+
// REMOVE_START
189+
Assert.True(hashIndexCreated);
190+
// REMOVE_END
184191

192+
// STEP_START add_hash_data
193+
db.HashSet("huser:1", new HashEntry[] {
194+
new("name", "Paul John"),
195+
new("email", "[email protected]"),
196+
new("age", 42),
197+
new("city", "London")
198+
});
199+
200+
db.HashSet("huser:2", new HashEntry[] {
201+
new("name", "Eden Zamir"),
202+
new("email", "[email protected]"),
203+
new("age", 29),
204+
new("city", "Tel Aviv")
205+
});
206+
207+
db.HashSet("huser:3", new HashEntry[] {
208+
new("name", "Paul Zamir"),
209+
new("email", "[email protected]"),
210+
new("age", 35),
211+
new("city", "Tel Aviv")
212+
});
213+
// STEP_END
214+
215+
// STEP_START query1_hash
216+
SearchResult findPaulHashResult = db.FT().Search(
217+
"hash-idx:users",
218+
new Query("Paul @age:[30 40]")
219+
);
220+
221+
foreach (Document doc in findPaulHashResult.Documents)
222+
{
223+
Console.WriteLine(
224+
$"Name: {doc["name"]}, email: {doc["email"]}, " +
225+
$"age: {doc["age"]}, city:{doc["city"]}"
226+
);
227+
}
228+
// >>> Name: Paul Zamir, email: [email protected], age: 35, ...
229+
// STEP_END
230+
// REMOVE_START
231+
Document d = findPaulHashResult.Documents[0];
232+
Assert.Equal(
233+
"Name: Paul Zamir, email: [email protected], age: 35, city:Tel Aviv",
234+
$"Name: {d["name"]}, email: {d["email"]}, " +
235+
$"age: {d["age"]}, city:{d["city"]}"
236+
);
237+
// REMOVE_END
185238
// HIDE_START
186239
}
187240
}

tests/Doc/PipeTransExample.cs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// EXAMPLE: pipe_trans_tutorial
2+
using NRedisStack;
3+
using StackExchange.Redis;
4+
//REMOVE_START
5+
using NRedisStack.Tests;
6+
7+
namespace Doc;
8+
[Collection("DocsTests")]
9+
//REMOVE_END
10+
public class PipeTransExample
11+
// REMOVE_START
12+
: AbstractNRedisStackTest, IDisposable
13+
// REMOVE_END
14+
{
15+
// REMOVE_START
16+
public PipeTransExample(EndpointsFixture fixture) : base(fixture) { }
17+
18+
[SkippableFact]
19+
// REMOVE_END
20+
public async Task run()
21+
{
22+
//REMOVE_START
23+
// This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection
24+
SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone);
25+
var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone);
26+
//REMOVE_END
27+
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
28+
var db = muxer.GetDatabase();
29+
// REMOVE_START
30+
db.KeyDelete(new RedisKey[] {
31+
"counter:1", "counter:2", "counter:3",
32+
"seat:0", "seat:1", "seat:2", "seat:3", "seat:4",
33+
"customer:39182",
34+
"Details"
35+
});
36+
// REMOVE_END
37+
38+
// STEP_START basic_pipe
39+
var pipeline = new Pipeline(db);
40+
41+
for (int i = 0; i < 5; i++)
42+
{
43+
pipeline.Db.StringSetAsync($"seat:{i}", $"#{i}");
44+
}
45+
pipeline.Execute();
46+
47+
var resp1 = db.StringGet("seat:0");
48+
Console.WriteLine(resp1); // >>> #0
49+
50+
var resp2 = db.StringGet("seat:3");
51+
Console.WriteLine(resp2); // >>> #3
52+
53+
var resp3 = db.StringGet("seat:4");
54+
Console.WriteLine(resp2); // >>> #4
55+
// STEP_END
56+
// REMOVE_START
57+
Assert.Equal("#0", resp1);
58+
Assert.Equal("#3", resp2);
59+
Assert.Equal("#4", resp3);
60+
// REMOVE_END
61+
62+
// STEP_START basic_trans
63+
var trans = new Transaction(db);
64+
65+
trans.Db.StringIncrementAsync("counter:1", 1);
66+
trans.Db.StringIncrementAsync("counter:2", 2);
67+
trans.Db.StringIncrementAsync("counter:3", 3);
68+
69+
trans.Execute();
70+
71+
var resp4 = db.StringGet("counter:1");
72+
Console.WriteLine(resp4); // >>> 1
73+
74+
var resp5 = db.StringGet("counter:2");
75+
Console.WriteLine(resp5); // >>> 2
76+
77+
var resp6 = db.StringGet("counter:3");
78+
Console.WriteLine(resp6); // >>> 3
79+
// STEP_END
80+
// REMOVE_START
81+
Assert.Equal("1", resp4);
82+
Assert.Equal("2", resp5);
83+
Assert.Equal("3", resp6);
84+
// REMOVE_END
85+
86+
// STEP_START trans_watch
87+
var watchedTrans = new Transaction(db);
88+
89+
watchedTrans.AddCondition(Condition.KeyNotExists("customer:39182"));
90+
91+
watchedTrans.Db.HashSetAsync(
92+
"customer:39182",
93+
new HashEntry[]{
94+
new HashEntry("name", "David"),
95+
new HashEntry("age", "27")
96+
}
97+
);
98+
99+
bool succeeded = watchedTrans.Execute();
100+
Console.WriteLine(succeeded); // >>> true
101+
// STEP_END
102+
// REMOVE_START
103+
Assert.True(succeeded);
104+
// REMOVE_END
105+
106+
// STEP_START when_condition
107+
bool resp7 = db.HashSet("Details", "SerialNumber", "12345");
108+
Console.WriteLine(resp7); // >>> true
109+
110+
db.HashSet("Details", "SerialNumber", "12345A", When.NotExists);
111+
string resp8 = db.HashGet("Details", "SerialNumber");
112+
Console.WriteLine(resp8); // >>> 12345
113+
114+
db.HashSet("Details", "SerialNumber", "12345A");
115+
string resp9 = db.HashGet("Details", "SerialNumber");
116+
Console.WriteLine(resp9); // >>> 12345A
117+
// STEP_END
118+
// REMOVE_START
119+
Assert.True(resp7);
120+
Assert.Equal("12345", resp8);
121+
Assert.Equal("12345A", resp9);
122+
// REMOVE_END
123+
}
124+
}

0 commit comments

Comments
 (0)