-
Notifications
You must be signed in to change notification settings - Fork 55
DOC-2554 added code samples for set datatype in C# #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andy-stark-redis
merged 10 commits into
master
from
DOC-2554-set-tutorial-examples-csharp
Jun 14, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c7ef82
DOC-2554 added code samples for set datatype
andy-stark-redis 5cfda89
DOC-2554 capitalised True and False in test text
andy-stark-redis 73da839
DOC-2554 fixed incorrect assert values
andy-stark-redis b66db8a
DOC-2554 fixed cross slot errors with hashtags
andy-stark-redis 47f022d
DOC-2554 fixed incorrect assert values
andy-stark-redis d3f5184
DOC-2554 removed test that appeared to have inconsistent results
andy-stark-redis 06efb55
DOC-2554 removed tests with inconsistent results
andy-stark-redis 4cbd1e9
Merge branch 'master' into DOC-2554-set-tutorial-examples-csharp
andy-stark-redis 5dc09ef
Merge branch 'master' into DOC-2554-set-tutorial-examples-csharp
andy-stark-redis f64f0fa
Merge branch 'master' into DOC-2554-set-tutorial-examples-csharp
andy-stark-redis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| // EXAMPLE: sets_tutorial | ||
| // HIDE_START | ||
|
|
||
| using System.Data.Common; | ||
| using NRedisStack.Tests; | ||
| using StackExchange.Redis; | ||
|
|
||
| // HIDE_END | ||
|
|
||
| //REMOVE_START | ||
| namespace NRedisStack.Doc; | ||
| [Collection("DocsTests")] | ||
| //REMOVE_END | ||
|
|
||
| // HIDE_START | ||
| public class SetsExample | ||
| { | ||
|
|
||
| [SkipIfRedis(Is.OSSCluster)] | ||
| public void run() | ||
| { | ||
| var muxer = ConnectionMultiplexer.Connect("localhost:6379"); | ||
| var db = muxer.GetDatabase(); | ||
| //REMOVE_START | ||
| // Clear any keys here before using them in tests. | ||
| bool delRes = db.KeyDelete("bikes:racing:france"); | ||
| delRes = db.KeyDelete("bikes:racing:usa"); | ||
| //REMOVE_END | ||
| // HIDE_END | ||
|
|
||
|
|
||
| // STEP_START sadd | ||
| long res1 = db.SetAdd("bikes:racing:france", new RedisValue[] { "bike:1" }); | ||
| Console.WriteLine(res1); // >>> 1 | ||
|
|
||
| long res2 = db.SetAdd("bikes:racing:france", new RedisValue[] { "bike:1" }); | ||
| Console.WriteLine(res2); // >>> 0 | ||
|
|
||
| long res3 = db.SetAdd("bikes:racing:france", new RedisValue[] { "bike:2", "bike:3" }); | ||
| Console.WriteLine(res3); // >>> 2 | ||
|
|
||
| long res4 = db.SetAdd("bikes:racing:usa", new RedisValue[] { "bike:1", "bike:4" }); | ||
| Console.WriteLine(res4); // >>> 2 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'sadd' step. | ||
| // REMOVE_START | ||
| Assert.Equal(1, res1); | ||
| Assert.Equal(0, res2); | ||
| Assert.Equal(2, res3); | ||
| Assert.Equal(2, res4); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START sismember | ||
| bool res5 = db.SetContains("bikes:racing:france", "bike:1"); | ||
| Console.WriteLine(res5); // >>> True | ||
|
|
||
| bool res6 = db.SetContains("bikes:racing:usa", "bike:2"); | ||
| Console.WriteLine(res6); // >>> False | ||
| // STEP_END | ||
|
|
||
| // Tests for 'sismember' step. | ||
| // REMOVE_START | ||
| Assert.True(res5); | ||
| Assert.False(res6); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START sinter | ||
| long res7 = db.SetAdd("{bikes:racing}:france", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); | ||
| long res8 = db.SetAdd("{bikes:racing}:usa", new RedisValue[] { "bike:1", "bike:4" }); | ||
|
|
||
| RedisValue[] res9 = db.SetCombine(SetOperation.Intersect, new RedisKey[] { "{bikes:racing}:france", "{bikes:racing}:usa" }); | ||
| Console.WriteLine(string.Join(", ", res9)); // >>> bike:1 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'sinter' step. | ||
| // REMOVE_START | ||
| Assert.Equal(3, res7); | ||
| Assert.Equal(2, res8); | ||
| Assert.Equal("bike:1", string.Join(", ", res9)); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START scard | ||
| long res10 = db.SetAdd("bikes:racing:france", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); | ||
| long res11 = db.SetLength("bikes:racing:france"); | ||
| Console.WriteLine(res11); // >>> 3 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'scard' step. | ||
| // REMOVE_START | ||
| Assert.Equal(3, res11); | ||
| delRes = db.KeyDelete("bikes:racing:france"); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START sadd_smembers | ||
| long res12 = db.SetAdd("bikes:racing:france", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); | ||
| RedisValue[] res13 = db.SetMembers("bikes:racing:france"); | ||
| Console.WriteLine(string.Join(", ", res13)); // >>> bike:3, bike:2, bike:1 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'sadd_smembers' step. | ||
| // REMOVE_START | ||
| Assert.Equal(3, res12); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START smismember | ||
| bool res14 = db.SetContains("bikes:racing:france", "bike:1"); | ||
| Console.WriteLine(res14); // >>> true | ||
|
|
||
| bool[] res15 = db.SetContains("bikes:racing:france", new RedisValue[] { "bike:2", "bike:3", "bike:4" }); | ||
| Console.WriteLine(string.Join(", ", res15)); // >>> True, True, False | ||
| // STEP_END | ||
|
|
||
| // Tests for 'smismember' step. | ||
| // REMOVE_START | ||
| Assert.True(res14); | ||
| Assert.Equal("True, True, False", string.Join(", ", res15)); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START sdiff | ||
| long res16 = db.SetAdd("{bikes:racing}:france", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); | ||
| long res17 = db.SetAdd("{bikes:racing}:usa", new RedisValue[] { "bike:1", "bike:4" }); | ||
| RedisValue[] res18 = db.SetCombine(SetOperation.Difference, new RedisKey[] { "{bikes:racing}:france", "{bikes:racing}:usa" }); | ||
| Console.WriteLine(string.Join(", ", res18)); // >>> bike:2, bike:3 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'sdiff' step. | ||
| // REMOVE_START | ||
| Assert.Equal(0, res16); | ||
| Assert.Equal(0, res17); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START multisets | ||
| long res19 = db.SetAdd("{bikes:racing}:france", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); | ||
| long res20 = db.SetAdd("{bikes:racing}:usa", new RedisValue[] { "bike:1", "bike:4" }); | ||
| long res21 = db.SetAdd("{bikes:racing}:italy", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4" }); | ||
|
|
||
| RedisValue[] res22 = db.SetCombine(SetOperation.Intersect, new RedisKey[] { "{bikes:racing}:france", "{bikes:racing}:usa", "{bikes:racing}:italy" }); | ||
| Console.WriteLine(string.Join(", ", res22)); // >>> bike:1 | ||
|
|
||
| RedisValue[] res23 = db.SetCombine(SetOperation.Union, new RedisKey[] { "{bikes:racing}:france", "{bikes:racing}:usa", "{bikes:racing}:italy" }); | ||
| Console.WriteLine(string.Join(", ", res23)); // >>> bike:1, bike:2, bike:3, bike:4 | ||
|
|
||
| RedisValue[] res24 = db.SetCombine(SetOperation.Difference, new RedisKey[] { "{bikes:racing}:france", "{bikes:racing}:usa", "{bikes:racing}:italy" }); | ||
| Console.WriteLine(string.Join(", ", res24)); // >>> <empty set> | ||
|
|
||
| RedisValue[] res25 = db.SetCombine(SetOperation.Difference, new RedisKey[] { "{bikes:racing}:usa", "{bikes:racing}:france" }); | ||
| Console.WriteLine(string.Join(", ", res25)); // >>> bike:4 | ||
|
|
||
| RedisValue[] res26 = db.SetCombine(SetOperation.Difference, new RedisKey[] { "{bikes:racing}:france", "{bikes:racing}:usa" }); | ||
| Console.WriteLine(string.Join(", ", res26)); // >>> bike:2, bike:3 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'multisets' step. | ||
| // REMOVE_START | ||
| Assert.Equal(0, res19); | ||
| Assert.Equal(0, res20); | ||
| Assert.Equal(4, res21); | ||
| Assert.Equal("bike:1", string.Join(", ", res22)); | ||
| Assert.Equal("", string.Join(", ", res24)); | ||
| Assert.Equal("bike:4", string.Join(", ", res25)); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // STEP_START srem | ||
| long res27 = db.SetAdd("bikes:racing:france", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); | ||
|
|
||
| bool res28 = db.SetRemove("bikes:racing:france", "bike:1"); | ||
| Console.WriteLine(res28); // >>> True | ||
|
|
||
| RedisValue res29 = db.SetPop("bikes:racing:france"); | ||
| Console.WriteLine(res29); // >>> bike:3 | ||
|
|
||
| RedisValue[] res30 = db.SetMembers("bikes:racing:france"); | ||
| Console.WriteLine(string.Join(", ", res30)); // >>> bike:2, bike:4, bike:5 | ||
|
|
||
| RedisValue res31 = db.SetRandomMember("bikes:racing:france"); | ||
| Console.WriteLine(res31); // >>> bike:4 | ||
| // STEP_END | ||
|
|
||
| // Tests for 'srem' step. | ||
| // REMOVE_START | ||
| Assert.Equal(2, res27); | ||
| Assert.True(res28); | ||
| // REMOVE_END | ||
|
|
||
|
|
||
| // HIDE_START | ||
| } | ||
| } | ||
| // HIDE_END | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.