|
| 1 | +// EXAMPLE: cms_tutorial |
| 2 | +// HIDE_START |
| 3 | + |
| 4 | +using NRedisStack.CountMinSketch.DataTypes; |
| 5 | +using NRedisStack.RedisStackCommands; |
| 6 | +using NRedisStack.Tests; |
| 7 | +using StackExchange.Redis; |
| 8 | + |
| 9 | +// HIDE_END |
| 10 | + |
| 11 | +// REMOVE_START |
| 12 | +namespace Doc; |
| 13 | +[Collection("DocsTests")] |
| 14 | +// REMOVE_END |
| 15 | + |
| 16 | +// HIDE_START |
| 17 | +public class Cms_tutorial |
| 18 | +{ |
| 19 | + |
| 20 | + [SkipIfRedis(Is.OSSCluster)] |
| 21 | + public void run() |
| 22 | + { |
| 23 | + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); |
| 24 | + var db = muxer.GetDatabase(); |
| 25 | + //REMOVE_START |
| 26 | + // Clear any keys here before using them in tests. |
| 27 | + db.KeyDelete("bikes:profit"); |
| 28 | + //REMOVE_END |
| 29 | + // HIDE_END |
| 30 | + |
| 31 | + |
| 32 | + // STEP_START cms |
| 33 | + bool res1 = db.CMS().InitByProb("bikes:profit", 0.001, 0.002); |
| 34 | + Console.WriteLine(res1); // >>> True |
| 35 | + |
| 36 | + long res2 = db.CMS().IncrBy("bikes:profit", "Smoky Mountain Striker", 100); |
| 37 | + Console.WriteLine(res2); // >>> 100 |
| 38 | + |
| 39 | + long[] res3 = db.CMS().IncrBy("bikes:profit", |
| 40 | + new Tuple<RedisValue, long>[]{ |
| 41 | + new Tuple<RedisValue, long>("Rocky Mountain Racer", 200), |
| 42 | + new Tuple<RedisValue, long>("Cloudy City Cruiser", 150) |
| 43 | + } |
| 44 | + ); |
| 45 | + Console.WriteLine(string.Join(", ", res3)); // >>> 200, 150 |
| 46 | + |
| 47 | + long[] res4 = db.CMS().Query("bikes:profit", new RedisValue[] { "Smoky Mountain Striker" }); |
| 48 | + Console.WriteLine(string.Join(", ", res4)); // >>> 100 |
| 49 | + |
| 50 | + CmsInformation res5 = db.CMS().Info("bikes:profit"); |
| 51 | + Console.WriteLine($"Width: {res5.Width}, Depth: {res5.Depth}, Count: {res5.Count}"); |
| 52 | + // >>> Width: 2000, Depth: 9, Count: 450 |
| 53 | + // STEP_END |
| 54 | + |
| 55 | + // Tests for 'cms' step. |
| 56 | + // REMOVE_START |
| 57 | + Assert.True(res1); |
| 58 | + Assert.Equal(100, res2); |
| 59 | + Assert.Equal("200, 150", string.Join(", ", res3)); |
| 60 | + Assert.Equal("100", string.Join(", ", res4)); |
| 61 | + Assert.Equal(2000, res5.Width); |
| 62 | + Assert.Equal(9, res5.Depth); |
| 63 | + Assert.Equal(450, res5.Count); |
| 64 | + // REMOVE_END |
| 65 | + |
| 66 | + |
| 67 | + // HIDE_START |
| 68 | + } |
| 69 | +} |
| 70 | +// HIDE_END |
| 71 | + |
0 commit comments