-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathBf_tutorial.cs
81 lines (66 loc) · 2.28 KB
/
Bf_tutorial.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
// EXAMPLE: bf_tutorial
// HIDE_START
using NRedisStack.RedisStackCommands;
using NRedisStack.Tests;
using StackExchange.Redis;
// HIDE_END
// REMOVE_START
namespace Doc;
[Collection("DocsTests")]
// REMOVE_END
// HIDE_START
public class Bf_tutorial
// REMOVE_START
: AbstractNRedisStackTest, IDisposable
// REMOVE_END
{
// REMOVE_START
public Bf_tutorial(EndpointsFixture fixture) : base(fixture) { }
[SkippableFact]
// 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.
db.KeyDelete("bikes:models");
//REMOVE_END
// HIDE_END
// STEP_START bloom
bool res1 = db.BF().Reserve("bikes:models", 0.01, 1000);
Console.WriteLine(res1); // >>> True
bool res2 = db.BF().Add("bikes:models", "Smoky Mountain Striker");
Console.WriteLine(res2); // >>> True
bool res3 = db.BF().Exists("bikes:models", "Smoky Mountain Striker");
Console.WriteLine(res3); // >>> True
bool[] res4 = db.BF().MAdd("bikes:models", new RedisValue[]{
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet"
});
Console.WriteLine(string.Join(", ", res4)); // >>> True, True, True
bool[] res5 = db.BF().MExists("bikes:models", new RedisValue[]{
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet"
});
Console.WriteLine(string.Join(", ", res5)); // >>> True, True, True
// STEP_END
// Tests for 'bloom' step.
// REMOVE_START
Assert.True(res1);
Assert.True(res2);
Assert.True(res3);
Assert.Equal("True, True, True", string.Join(", ", res4));
Assert.Equal("True, True, True", string.Join(", ", res5));
// REMOVE_END
// HIDE_START
}
}
// HIDE_END