|
| 1 | +using NRedisStack; |
| 2 | +using NRedisStack.Core.DataTypes; |
| 3 | +using StackExchange.Redis; |
| 4 | + |
| 5 | +public class PackageTest |
| 6 | +{ |
| 7 | + public static void Main() |
| 8 | + { |
| 9 | + ConfigurationOptions configurationOptions = new ConfigurationOptions(); |
| 10 | + configurationOptions.SyncTimeout = 20000; |
| 11 | + configurationOptions.EndPoints.Add("localhost:6379"); |
| 12 | + ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions); |
| 13 | + IDatabase db = redis.GetDatabase(); |
| 14 | + |
| 15 | + db.Execute("FLUSHALL"); |
| 16 | + |
| 17 | + db.SortedSetAdd("X", "foo", 5.1); |
| 18 | + db.SortedSetAdd("X", "bar", 8.4); |
| 19 | + db.SortedSetAdd("X", "baz", 6.7); |
| 20 | + |
| 21 | + var result = db.BzmPop(0, new[] { new RedisKey("X") }, MinMaxModifier.Max, count: 2); |
| 22 | + Assert(2 == result!.Item2.Count); |
| 23 | + Assert("bar" == result.Item2[0].Value); |
| 24 | + Assert("baz" == result.Item2[1].Value); |
| 25 | + |
| 26 | + result = db.BzmPop(0, "X", MinMaxModifier.Min); |
| 27 | + Assert(1 == result!.Item2.Count); |
| 28 | + Assert("foo" == result!.Item2[0].Value); |
| 29 | + |
| 30 | + db.SortedSetAdd("X", "foo", 5.1); |
| 31 | + db.SortedSetAdd("X", "bar", 8.4); |
| 32 | + db.SortedSetAdd("X", "baz", 6.7); |
| 33 | + |
| 34 | + var singleResult = db.BzPopMin("X", 0); |
| 35 | + Assert("foo" == singleResult!.Item2.Value); |
| 36 | + |
| 37 | + singleResult = db.BzPopMax("X", 0); |
| 38 | + Assert("bar" == singleResult!.Item2.Value); |
| 39 | + |
| 40 | + Console.WriteLine("All good."); |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Poor Man's assert, since we don't want to depend on NUnit. |
| 45 | + /// </summary> |
| 46 | + private static void Assert(bool condition) |
| 47 | + { |
| 48 | + if (!condition) |
| 49 | + { |
| 50 | + throw new System.Exception(); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments