This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 876
/
RedisClientTests.cs
670 lines (538 loc) · 21.8 KB
/
RedisClientTests.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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using NUnit.Framework;
using ServiceStack.Common;
using ServiceStack.Redis.Support.Locking;
using ServiceStack.Text;
namespace ServiceStack.Redis.Tests
{
[TestFixture, Category("Integration")]
public class RedisClientTests
: RedisClientTestsBase
{
const string Value = "Value";
public override void OnBeforeEachTest()
{
base.OnBeforeEachTest();
Redis.NamespacePrefix = "RedisClientTests";
}
[Test]
public void Can_Set_and_Get_string()
{
Redis.SetValue("key", Value);
var valueBytes = Redis.Get("key");
var valueString = GetString(valueBytes);
Redis.Remove("key");
Assert.That(valueString, Is.EqualTo(Value));
}
[Test]
public void Can_Set_and_Get_key_with_space()
{
Redis.SetValue("key with space", Value);
var valueBytes = Redis.Get("key with space");
var valueString = GetString(valueBytes);
Redis.Remove("key with space");
Assert.That(valueString, Is.EqualTo(Value));
}
[Test]
public void Can_Set_and_Get_key_with_spaces()
{
const string key = "key with spaces";
Redis.SetValue(key, Value);
var valueBytes = Redis.Get(key);
var valueString = GetString(valueBytes);
Assert.That(valueString, Is.EqualTo(Value));
}
[Test]
public void Can_Set_and_Get_key_with_all_byte_values()
{
const string key = "bytesKey";
var value = new byte[256];
for (var i = 0; i < value.Length; i++)
{
value[i] = (byte)i;
}
Redis.Set(key, value);
var resultValue = Redis.Get(key);
Assert.That(resultValue, Is.EquivalentTo(value));
}
[Test]
public void GetKeys_returns_matching_collection()
{
Redis.Set("ss-tests:a1", "One");
Redis.Set("ss-tests:a2", "One");
Redis.Set("ss-tests:b3", "One");
var matchingKeys = Redis.SearchKeys("ss-tests:a*");
Assert.That(matchingKeys.Count, Is.EqualTo(2));
}
[Test]
public void GetKeys_on_non_existent_keys_returns_empty_collection()
{
var matchingKeys = Redis.SearchKeys("ss-tests:NOTEXISTS");
Assert.That(matchingKeys.Count, Is.EqualTo(0));
}
[Test]
public void Can_get_Types()
{
Redis.SetValue("string", "string");
Redis.AddItemToList("list", "list");
Redis.AddItemToSet("set", "set");
Redis.AddItemToSortedSet("sortedset", "sortedset");
Redis.SetEntryInHash("hash", "key", "val");
Assert.That(Redis.GetEntryType("nokey"), Is.EqualTo(RedisKeyType.None));
Assert.That(Redis.GetEntryType("string"), Is.EqualTo(RedisKeyType.String));
Assert.That(Redis.GetEntryType("list"), Is.EqualTo(RedisKeyType.List));
Assert.That(Redis.GetEntryType("set"), Is.EqualTo(RedisKeyType.Set));
Assert.That(Redis.GetEntryType("sortedset"), Is.EqualTo(RedisKeyType.SortedSet));
Assert.That(Redis.GetEntryType("hash"), Is.EqualTo(RedisKeyType.Hash));
}
[Test]
public void Can_delete_keys()
{
Redis.SetValue("key", "val");
Assert.That(Redis.ContainsKey("key"), Is.True);
Redis.Del("key");
Assert.That(Redis.ContainsKey("key"), Is.False);
var keysMap = new Dictionary<string, string>();
10.Times(i => keysMap.Add("key" + i, "val" + i));
Redis.SetAll(keysMap);
10.Times(i => Assert.That(Redis.ContainsKey("key" + i), Is.True));
Redis.Del(keysMap.Keys.ToArray());
10.Times(i => Assert.That(Redis.ContainsKey("key" + i), Is.False));
}
[Test]
public void Can_get_RandomKey()
{
Redis.Db = 15;
var keysMap = new Dictionary<string, string>();
10.Times(i => keysMap.Add(Redis.NamespacePrefix + "key" + i, "val" + i));
Redis.SetAll(keysMap);
var randKey = Redis.RandomKey();
Assert.That(keysMap.ContainsKey(randKey), Is.True);
}
[Test]
public void Can_RenameKey()
{
Redis.SetValue("oldkey", "val");
Redis.Rename("oldkey", "newkey");
Assert.That(Redis.ContainsKey("oldkey"), Is.False);
Assert.That(Redis.ContainsKey("newkey"), Is.True);
}
[Test]
public void Can_Expire()
{
Redis.SetValue("key", "val");
Redis.Expire("key", 1);
Assert.That(Redis.ContainsKey("key"), Is.True);
Thread.Sleep(2000);
Assert.That(Redis.ContainsKey("key"), Is.False);
}
[Test]
public void Can_Expire_Ms()
{
Redis.SetValue("key", "val");
Redis.ExpireEntryIn("key", TimeSpan.FromMilliseconds(100));
Assert.That(Redis.ContainsKey("key"), Is.True);
Thread.Sleep(500);
Assert.That(Redis.ContainsKey("key"), Is.False);
}
[Ignore("Changes in system clock can break test")]
[Test]
public void Can_ExpireAt()
{
Redis.SetValue("key", "val");
var unixNow = DateTime.Now.ToUnixTime();
var in2Secs = unixNow + 2;
Redis.ExpireAt("key", in2Secs);
Assert.That(Redis.ContainsKey("key"), Is.True);
Thread.Sleep(3000);
Assert.That(Redis.ContainsKey("key"), Is.False);
}
[Test]
public void Can_GetTimeToLive()
{
Redis.SetValue("key", "val");
Redis.Expire("key", 10);
var ttl = Redis.GetTimeToLive("key");
Assert.That(ttl.Value.TotalSeconds, Is.GreaterThanOrEqualTo(9));
Thread.Sleep(1700);
ttl = Redis.GetTimeToLive("key");
Assert.That(ttl.Value.TotalSeconds, Is.LessThanOrEqualTo(9));
}
[Test]
public void Can_GetServerTime()
{
var now = Redis.GetServerTime();
now.Kind.PrintDump();
now.ToString("D").Print();
now.ToString("T").Print();
"UtcNow".Print();
DateTime.UtcNow.ToString("D").Print();
DateTime.UtcNow.ToString("T").Print();
Assert.That(now.Date, Is.EqualTo(DateTime.UtcNow.Date));
}
[Test]
public void Can_Ping()
{
Assert.That(Redis.Ping(), Is.True);
}
[Test]
public void Can_Echo()
{
Assert.That(Redis.Echo("Hello"), Is.EqualTo("Hello"));
}
[Test]
public void Can_SlaveOfNoOne()
{
Redis.SlaveOfNoOne();
}
[Test]
public void Can_Save()
{
try
{
Redis.Save();
}
catch (RedisResponseException e)
{
// if exception has that message then it still proves that BgSave works as expected.
if (e.Message.StartsWith("Can't BGSAVE while AOF log rewriting is in progress")
|| e.Message.StartsWith("An AOF log rewriting in progress: can't BGSAVE right now")
|| e.Message.StartsWith("Background save already in progress")
|| e.Message.StartsWith("Another child process is active (AOF?): can't BGSAVE right now"))
return;
throw;
}
}
[Test]
public void Can_BgSave()
{
try
{
Redis.BgSave();
}
catch (RedisResponseException e)
{
// if exception has that message then it still proves that BgSave works as expected.
if (e.Message.StartsWith("Can't BGSAVE while AOF log rewriting is in progress")
|| e.Message.StartsWith("An AOF log rewriting in progress: can't BGSAVE right now")
|| e.Message.StartsWith("Background save already in progress")
|| e.Message.StartsWith("Another child process is active (AOF?): can't BGSAVE right now"))
return;
throw;
}
}
[Test]
public void Can_Quit()
{
Redis.Quit();
Redis.NamespacePrefix = null;
CleanMask = null;
}
[Test]
public void Can_BgRewriteAof()
{
Redis.BgRewriteAof();
}
[Test]
[Ignore("Works too well and shutdown the server")]
public void Can_Shutdown()
{
Redis.Shutdown();
}
[Test]
public void Can_get_Keys_with_pattern()
{
5.Times(i => Redis.SetValue("k1:" + i, "val"));
5.Times(i => Redis.SetValue("k2:" + i, "val"));
var keys = Redis.Keys("k1:*");
Assert.That(keys.Length, Is.EqualTo(5));
var scanKeys = Redis.ScanAllKeys("k1:*").ToArray();
Assert.That(scanKeys.Length, Is.EqualTo(5));
}
[Test]
public void Can_GetAll()
{
var keysMap = new Dictionary<string, string>();
10.Times(i => keysMap.Add("key" + i, "val" + i));
Redis.SetAll(keysMap);
var map = Redis.GetAll<string>(keysMap.Keys);
var mapKeys = Redis.GetValues(keysMap.Keys.ToList<string>());
foreach (var entry in keysMap)
{
Assert.That(map.ContainsKey(entry.Key), Is.True);
Assert.That(mapKeys.Contains(entry.Value), Is.True);
}
}
[Test]
public void Can_GetValues_JSON_strings()
{
var val = "{\"AuthorId\":0,\"Created\":\"\\/Date(1345961754013)\\/\",\"Name\":\"test\",\"Base64\":\"BQELAAEBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAViA/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP8BWAFYgP8BWAFYAViA/wFYAVgBWID/AVgBWAFYgP8BWAFYAViA/4D/gP+A/4D/AVgBWID/gP8BWID/gP8BWID/gP+A/wFYgP+A/4D/gP8BWID/gP+A/4D/gP+A/wFYAViA/4D/AViA/4D/AVgBWAFYgP8BWAFYAViA/4D/AViA/4D/gP+A/4D/gP8BWAFYgP+A/wFYgP+A/wFYgP+A/4D/gP+A/wFYgP+A/wFYgP+A/4D/gP+A/4D/AVgBWID/gP8BWID/gP8BWAFYAViA/wFYAVgBWID/gP8BWID/gP+A/4D/gP+A/wFYAViA/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP8BWAFYgP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/AVgBWID/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/wFYAViA/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP8BWAFYgP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/AVgBWID/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/wFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}";
Redis.SetValue("UserLevel/1", val);
var vals = Redis.GetValues(new List<string>(new[] { "UserLevel/1" }));
Assert.That(vals.Count, Is.EqualTo(1));
Assert.That(vals[0], Is.EqualTo(val));
}
[Test]
public void Can_AcquireLock()
{
// guid here is to prevent competition between concurrent runtime tests
var key = PrefixedKey("AcquireLockKeyTimeOut:" + Guid.NewGuid());
var lockKey = PrefixedKey("Can_AcquireLock_TimeOut:" + Guid.NewGuid());
Redis.IncrementValue(key); //1
var asyncResults = 5.TimesAsync(i =>
IncrementKeyInsideLock(key, lockKey, i, new RedisClient(TestConfig.SingleHost) { NamespacePrefix = Redis.NamespacePrefix }));
asyncResults.WaitAll(TimeSpan.FromSeconds(5));
var val = Redis.Get<int>(key);
Assert.That(val, Is.EqualTo(1 + 5));
}
private void IncrementKeyInsideLock(String key, String lockKey, int clientNo, IRedisClient client)
{
using (client.AcquireLock(lockKey))
{
Debug.WriteLine(String.Format("client {0} acquired lock", clientNo));
var val = client.Get<int>(key);
Thread.Sleep(200);
client.Set(key, val + 1);
Debug.WriteLine(String.Format("client {0} released lock", clientNo));
}
}
[Test]
public void Can_AcquireLock_TimeOut()
{
// guid here is to prevent competition between concurrent runtime tests
var key = PrefixedKey("AcquireLockKeyTimeOut:" + Guid.NewGuid());
var lockKey = PrefixedKey("Can_AcquireLock_TimeOut:" + Guid.NewGuid());
Redis.IncrementValue(key); //1
var acquiredLock = Redis.AcquireLock(lockKey);
var waitFor = TimeSpan.FromMilliseconds(1000);
var now = DateTime.Now;
try
{
using (var client = new RedisClient(TestConfig.SingleHost))
{
using (client.AcquireLock(lockKey, waitFor))
{
Redis.IncrementValue(key); //2
}
}
}
catch (TimeoutException)
{
var val = Redis.Get<int>(key);
Assert.That(val, Is.EqualTo(1));
var timeTaken = DateTime.Now - now;
Assert.That(timeTaken.TotalMilliseconds > waitFor.TotalMilliseconds, Is.True);
Assert.That(timeTaken.TotalMilliseconds < waitFor.TotalMilliseconds + 1000, Is.True);
return;
}
finally
{
Redis.Remove(key);
Redis.Remove(lockKey);
}
Assert.Fail("should have Timed out");
}
[Test]
public void Can_Append()
{
const string expectedString = "Hello, " + "World!";
Redis.SetValue("key", "Hello, ");
var currentLength = Redis.AppendToValue("key", "World!");
Assert.That(currentLength, Is.EqualTo(expectedString.Length));
var val = Redis.GetValue("key");
Assert.That(val, Is.EqualTo(expectedString));
}
[Test]
public void Can_GetRange()
{
const string helloWorld = "Hello, World!";
Redis.SetValue("key", helloWorld);
var fromIndex = "Hello, ".Length;
var toIndex = "Hello, World".Length - 1;
var expectedString = helloWorld.Substring(fromIndex, toIndex - fromIndex + 1);
var world = Redis.GetRange("key", fromIndex, toIndex);
Assert.That(world.Length, Is.EqualTo(expectedString.Length));
}
[Test]
public void Can_create_distributed_lock()
{
var key = "lockkey";
int lockTimeout = 2;
var distributedLock = new DistributedLock();
long lockExpire;
Assert.AreEqual(distributedLock.Lock(key, lockTimeout, lockTimeout, out lockExpire, Redis), DistributedLock.LOCK_ACQUIRED);
//can't re-lock
distributedLock = new DistributedLock();
Assert.AreEqual(distributedLock.Lock(key, lockTimeout, lockTimeout, out lockExpire, Redis), DistributedLock.LOCK_NOT_ACQUIRED);
// re-acquire lock after timeout
Thread.Sleep(lockTimeout * 1000 + 1000);
distributedLock = new DistributedLock();
Assert.AreEqual(distributedLock.Lock(key, lockTimeout, lockTimeout, out lockExpire, Redis), DistributedLock.LOCK_RECOVERED);
Assert.IsTrue(distributedLock.Unlock(key, lockExpire, Redis));
//can now lock
distributedLock = new DistributedLock();
Assert.AreEqual(distributedLock.Lock(key, lockTimeout, lockTimeout, out lockExpire, Redis), DistributedLock.LOCK_ACQUIRED);
//cleanup
Assert.IsTrue(distributedLock.Unlock(key, lockExpire, Redis));
}
public class MyPoco
{
public int Id { get; set; }
public string Name { get; set; }
}
[Test]
public void Can_StoreObject()
{
object poco = new MyPoco { Id = 1, Name = "Test" };
Redis.StoreObject(poco);
Assert.That(Redis.GetValue(Redis.NamespacePrefix + "urn:mypoco:1"), Is.EqualTo("{\"Id\":1,\"Name\":\"Test\"}"));
Assert.That(Redis.PopItemFromSet(Redis.NamespacePrefix + "ids:MyPoco"), Is.EqualTo("1"));
}
[Test]
public void Can_store_multiple_keys()
{
var keys = 5.Times(x => "key" + x);
var vals = 5.Times(x => "val" + x);
using (var redis = RedisClient.New())
{
redis.SetAll(keys, vals);
var all = redis.GetValues(keys);
Assert.AreEqual(vals, all);
}
}
[Test]
public void Can_store_Dictionary()
{
var keys = 5.Times(x => "key" + x);
var vals = 5.Times(x => "val" + x);
var map = new Dictionary<string, string>();
keys.ForEach(x => map[x] = "val" + x);
using (var redis = RedisClient.New())
{
redis.SetAll(map);
var all = redis.GetValuesMap(keys);
Assert.AreEqual(map, all);
}
}
[Test]
public void Can_store_Dictionary_as_objects()
{
var map = new Dictionary<string, object>();
map["key_a"] = "123";
map["key_b"] = null;
using (var redis = RedisClient.New())
{
redis.SetAll(map);
Assert.That(redis.Get<string>("key_a"), Is.EqualTo("123"));
Assert.That(redis.Get("key_b"), Is.EqualTo(""));
}
}
[Test]
public void Can_store_Dictionary_as_bytes()
{
var map = new Dictionary<string, byte[]>();
map["key_a"] = "123".ToUtf8Bytes();
map["key_b"] = null;
using (var redis = RedisClient.New())
{
redis.SetAll(map);
Assert.That(redis.Get<string>("key_a"), Is.EqualTo("123"));
Assert.That(redis.Get("key_b"), Is.EqualTo(""));
}
}
[Test]
public void Should_reset_slowlog()
{
using (var redis = RedisClient.New())
{
redis.SlowlogReset();
}
}
[Test]
public void Can_get_slowlog()
{
using (var redis = RedisClient.New())
{
var log = redis.GetSlowlog(10);
foreach (var t in log)
{
Console.WriteLine(t.Id);
Console.WriteLine(t.Duration);
Console.WriteLine(t.Timestamp);
Console.WriteLine(string.Join(":", t.Arguments));
}
}
}
[Test]
public void Can_change_db_at_runtime()
{
using (var redis = new RedisClient(TestConfig.SingleHost, TestConfig.RedisPort, db: 1))
{
var val = Environment.TickCount;
var key = "test" + val;
try
{
redis.Set(key, val);
redis.ChangeDb(2);
Assert.That(redis.Get<int>(key), Is.EqualTo(0));
redis.ChangeDb(1);
Assert.That(redis.Get<int>(key), Is.EqualTo(val));
redis.Dispose();
}
finally
{
redis.ChangeDb(1);
redis.Del(key);
}
}
}
[Test]
public void Can_Set_Expire_Seconds()
{
Redis.SetValue("key", "val", expireIn: TimeSpan.FromSeconds(1));
Assert.That(Redis.ContainsKey("key"), Is.True);
Thread.Sleep(2000);
Assert.That(Redis.ContainsKey("key"), Is.False);
}
[Test]
public void Can_Set_Expire_MilliSeconds()
{
Redis.SetValue("key", "val", expireIn: TimeSpan.FromMilliseconds(1000));
Assert.That(Redis.ContainsKey("key"), Is.True);
Thread.Sleep(2000);
Assert.That(Redis.ContainsKey("key"), Is.False);
}
[Test]
public void Can_Set_Expire_Seconds_if_exists()
{
Assert.That(Redis.SetValueIfExists("key", "val", expireIn: TimeSpan.FromMilliseconds(1500)),
Is.False);
Assert.That(Redis.ContainsKey("key"), Is.False);
Redis.SetValue("key", "val");
Assert.That(Redis.SetValueIfExists("key", "val", expireIn: TimeSpan.FromMilliseconds(1000)),
Is.True);
Assert.That(Redis.ContainsKey("key"), Is.True);
Thread.Sleep(2000);
Assert.That(Redis.ContainsKey("key"), Is.False);
}
[Test]
public void Can_Set_Expire_Seconds_if_not_exists()
{
Assert.That(Redis.SetValueIfNotExists("key", "val", expireIn: TimeSpan.FromMilliseconds(1000)),
Is.True);
Assert.That(Redis.ContainsKey("key"), Is.True);
Assert.That(Redis.SetValueIfNotExists("key", "val", expireIn: TimeSpan.FromMilliseconds(1000)),
Is.False);
Thread.Sleep(2000);
Assert.That(Redis.ContainsKey("key"), Is.False);
Redis.Remove("key");
Redis.SetValueIfNotExists("key", "val", expireIn: TimeSpan.FromMilliseconds(1000));
Assert.That(Redis.ContainsKey("key"), Is.True);
}
}
}