forked from redis/NRedisStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmdsGenericExample.cs
450 lines (258 loc) · 8.54 KB
/
CmdsGenericExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
// EXAMPLE: cmds_generic
// HIDE_START
using NRedisStack.Tests;
using StackExchange.Redis;
// HIDE_END
// REMOVE_START
namespace Doc;
[Collection("DocsTests")]
// REMOVE_END
// HIDE_START
public class CmdsGenericExample
// REMOVE_START
: AbstractNRedisStackTest, IDisposable
// REMOVE_END
{
// REMOVE_START
public CmdsGenericExample(EndpointsFixture fixture) : base(fixture) { }
[SkipIfRedis(Comparison.LessThan, "7.0.0")]
[InlineData] // No parameters passed, but still uses Theory
// REMOVE_END
public void run()
{
//REMOVE_START
// This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection
SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone);
var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone);
//REMOVE_END
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
//REMOVE_START
// Clear any keys here before using them in tests.
//REMOVE_END
// HIDE_END
// STEP_START copy
// STEP_END
// Tests for 'copy' step.
// REMOVE_START
// REMOVE_END
// STEP_START del
bool delResult1 = db.StringSet("key1", "Hello");
Console.WriteLine(delResult1); // >>> true
bool delResult2 = db.StringSet("key2", "World");
Console.WriteLine(delResult2); // >>> true
long delResult3 = db.KeyDelete(new RedisKey[] { "key1", "key2", "key3" });
Console.WriteLine(delResult3); // >>> 2
// STEP_END
// Tests for 'del' step.
// REMOVE_START
Assert.True(delResult1);
Assert.True(delResult2);
Assert.Equal(2, delResult3);
// REMOVE_END
// STEP_START dump
// STEP_END
// Tests for 'dump' step.
// REMOVE_START
// REMOVE_END
// STEP_START exists
// STEP_END
// Tests for 'exists' step.
// REMOVE_START
// REMOVE_END
// REMOVE_START
// REMOVE_END
// STEP_START expire
bool expireResult1 = db.StringSet("mykey", "Hello");
Console.WriteLine(expireResult1); // >>> true
bool expireResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10));
Console.WriteLine(expireResult2); // >>> true
TimeSpan expireResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
Console.WriteLine(Math.Round(expireResult3.TotalSeconds)); // >>> 10
bool expireResult4 = db.StringSet("mykey", "Hello World");
Console.WriteLine(expireResult4); // >>> true
TimeSpan expireResult5 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
Console.WriteLine(Math.Round(expireResult5.TotalSeconds).ToString()); // >>> 0
bool expireResult6 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasExpiry);
Console.WriteLine(expireResult6); // >>> false
TimeSpan expireResult7 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
Console.WriteLine(Math.Round(expireResult7.TotalSeconds)); // >>> 0
bool expireResult8 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasNoExpiry);
Console.WriteLine(expireResult8); // >>> true
TimeSpan expireResult9 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
Console.WriteLine(Math.Round(expireResult9.TotalSeconds)); // >>> 10
// STEP_END
// Tests for 'expire' step.
// REMOVE_START
Assert.True(expireResult1);
Assert.True(expireResult2);
Assert.Equal(10, Math.Round(expireResult3.TotalSeconds));
Assert.True(expireResult4);
Assert.Equal(0, Math.Round(expireResult5.TotalSeconds));
Assert.False(expireResult6);
Assert.Equal(0, Math.Round(expireResult7.TotalSeconds));
Assert.True(expireResult8);
Assert.Equal(10, Math.Round(expireResult9.TotalSeconds));
db.KeyDelete("mykey");
// REMOVE_END
// STEP_START expireat
// STEP_END
// Tests for 'expireat' step.
// REMOVE_START
// REMOVE_END
// STEP_START expiretime
// STEP_END
// Tests for 'expiretime' step.
// REMOVE_START
// REMOVE_END
// STEP_START keys
// STEP_END
// Tests for 'keys' step.
// REMOVE_START
// REMOVE_END
// STEP_START migrate
// STEP_END
// Tests for 'migrate' step.
// REMOVE_START
// REMOVE_END
// STEP_START move
// STEP_END
// Tests for 'move' step.
// REMOVE_START
// REMOVE_END
// STEP_START object_encoding
// STEP_END
// Tests for 'object_encoding' step.
// REMOVE_START
// REMOVE_END
// STEP_START object_freq
// STEP_END
// Tests for 'object_freq' step.
// REMOVE_START
// REMOVE_END
// STEP_START object_idletime
// STEP_END
// Tests for 'object_idletime' step.
// REMOVE_START
// REMOVE_END
// STEP_START object_refcount
// STEP_END
// Tests for 'object_refcount' step.
// REMOVE_START
// REMOVE_END
// STEP_START persist
// STEP_END
// Tests for 'persist' step.
// REMOVE_START
// REMOVE_END
// STEP_START pexpire
// STEP_END
// Tests for 'pexpire' step.
// REMOVE_START
// REMOVE_END
// STEP_START pexpireat
// STEP_END
// Tests for 'pexpireat' step.
// REMOVE_START
// REMOVE_END
// STEP_START pexpiretime
// STEP_END
// Tests for 'pexpiretime' step.
// REMOVE_START
// REMOVE_END
// STEP_START pttl
// STEP_END
// Tests for 'pttl' step.
// REMOVE_START
// REMOVE_END
// STEP_START randomkey
// STEP_END
// Tests for 'randomkey' step.
// REMOVE_START
// REMOVE_END
// STEP_START rename
// STEP_END
// Tests for 'rename' step.
// REMOVE_START
// REMOVE_END
// STEP_START renamenx
// STEP_END
// Tests for 'renamenx' step.
// REMOVE_START
// REMOVE_END
// STEP_START restore
// STEP_END
// Tests for 'restore' step.
// REMOVE_START
// REMOVE_END
// STEP_START scan1
// STEP_END
// Tests for 'scan1' step.
// REMOVE_START
// REMOVE_END
// STEP_START scan2
// STEP_END
// Tests for 'scan2' step.
// REMOVE_START
// REMOVE_END
// STEP_START scan3
// STEP_END
// Tests for 'scan3' step.
// REMOVE_START
// REMOVE_END
// STEP_START scan4
// STEP_END
// Tests for 'scan4' step.
// REMOVE_START
// REMOVE_END
// STEP_START sort
// STEP_END
// Tests for 'sort' step.
// REMOVE_START
// REMOVE_END
// STEP_START sort_ro
// STEP_END
// Tests for 'sort_ro' step.
// REMOVE_START
// REMOVE_END
// STEP_START touch
// STEP_END
// Tests for 'touch' step.
// REMOVE_START
// REMOVE_END
// STEP_START ttl
bool ttlResult1 = db.StringSet("mykey", "Hello");
Console.WriteLine(ttlResult1); // >>> true
bool ttlResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10));
Console.WriteLine(ttlResult2);
TimeSpan ttlResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
string ttlRes = Math.Round(ttlResult3.TotalSeconds).ToString();
Console.WriteLine(Math.Round(ttlResult3.TotalSeconds)); // >>> 10
// STEP_END
// Tests for 'ttl' step.
// REMOVE_START
// REMOVE_END
// STEP_START type
// STEP_END
// Tests for 'type' step.
// REMOVE_START
// REMOVE_END
// STEP_START unlink
// STEP_END
// Tests for 'unlink' step.
// REMOVE_START
// REMOVE_END
// STEP_START wait
// STEP_END
// Tests for 'wait' step.
// REMOVE_START
// REMOVE_END
// STEP_START waitaof
// STEP_END
// Tests for 'waitaof' step.
// REMOVE_START
// REMOVE_END
// HIDE_START
}
}
// HIDE_END