-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathCms_tutorial.cs
82 lines (67 loc) · 2.46 KB
/
Cms_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
81
// EXAMPLE: cms_tutorial
// HIDE_START
using NRedisStack.CountMinSketch.DataTypes;
using NRedisStack.RedisStackCommands;
using NRedisStack.Tests;
using StackExchange.Redis;
// HIDE_END
// REMOVE_START
namespace Doc;
[Collection("DocsTests")]
// REMOVE_END
// HIDE_START
public class Cms_tutorial
// REMOVE_START
: AbstractNRedisStackTest, IDisposable
// REMOVE_END
{
// REMOVE_START
public Cms_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:profit");
//REMOVE_END
// HIDE_END
// STEP_START cms
bool res1 = db.CMS().InitByProb("bikes:profit", 0.001, 0.002);
Console.WriteLine(res1); // >>> True
long res2 = db.CMS().IncrBy("bikes:profit", "Smoky Mountain Striker", 100);
Console.WriteLine(res2); // >>> 100
long[] res3 = db.CMS().IncrBy("bikes:profit",
new Tuple<RedisValue, long>[]{
new Tuple<RedisValue, long>("Rocky Mountain Racer", 200),
new Tuple<RedisValue, long>("Cloudy City Cruiser", 150)
}
);
Console.WriteLine(string.Join(", ", res3)); // >>> 200, 150
long[] res4 = db.CMS().Query("bikes:profit", new RedisValue[] { "Smoky Mountain Striker" });
Console.WriteLine(string.Join(", ", res4)); // >>> 100
CmsInformation res5 = db.CMS().Info("bikes:profit");
Console.WriteLine($"Width: {res5.Width}, Depth: {res5.Depth}, Count: {res5.Count}");
// >>> Width: 2000, Depth: 9, Count: 450
// STEP_END
// Tests for 'cms' step.
// REMOVE_START
Assert.True(res1);
Assert.Equal(100, res2);
Assert.Equal("200, 150", string.Join(", ", res3));
Assert.Equal("100", string.Join(", ", res4));
Assert.Equal(2000, res5.Width);
Assert.Equal(9, res5.Depth);
Assert.Equal(450, res5.Count);
// REMOVE_END
// HIDE_START
}
}
// HIDE_END