|
4 | 4 | using StackExchange.Redis; |
5 | 5 | using Moq; |
6 | 6 | using NRedisStack.RedisStackCommands; |
7 | | - |
| 7 | +using NRedisStack.Json.DataTypes; |
8 | 8 |
|
9 | 9 | namespace NRedisStack.Tests; |
10 | 10 |
|
@@ -725,6 +725,63 @@ public async Task GetAsync() |
725 | 725 | Assert.Equal(35, people[1]!.Age); |
726 | 726 | } |
727 | 727 |
|
| 728 | + [Fact] |
| 729 | + [Trait("Category","edge")] |
| 730 | + public void MSet() |
| 731 | + { |
| 732 | + IJsonCommands commands = new JsonCommands(redisFixture.Redis.GetDatabase()); |
| 733 | + var keys = CreateKeyNames(2); |
| 734 | + var key1 = keys[0]; |
| 735 | + var key2 = keys[1]; |
| 736 | + |
| 737 | + KeyValuePath[] values = new[] |
| 738 | + { |
| 739 | + new KeyValuePath(key1, new { a = "hello" }), |
| 740 | + new KeyValuePath(key2, new { a = "world" }) |
| 741 | + }; |
| 742 | + commands.MSet(values) |
| 743 | +; |
| 744 | + var result = commands.MGet(keys.Select(x => new RedisKey(x)).ToArray(), "$.a"); |
| 745 | + |
| 746 | + Assert.Equal("[\"hello\"]", result[0].ToString()); |
| 747 | + Assert.Equal("[\"world\"]", result[1].ToString()); |
| 748 | + |
| 749 | + // test errors: |
| 750 | + Assert.Throws<ArgumentOutOfRangeException>(() => commands.MSet(new KeyValuePath[0])); |
| 751 | + |
| 752 | + } |
| 753 | + |
| 754 | + [Fact] |
| 755 | + [Trait("Category","edge")] |
| 756 | + public async Task MSetAsync() |
| 757 | + { |
| 758 | + IJsonCommandsAsync commands = new JsonCommands(redisFixture.Redis.GetDatabase()); |
| 759 | + var keys = CreateKeyNames(2); |
| 760 | + var key1 = keys[0]; |
| 761 | + var key2 = keys[1]; |
| 762 | + KeyValuePath[] values = new[] |
| 763 | + { |
| 764 | + new KeyValuePath(key1, new { a = "hello" }), |
| 765 | + new KeyValuePath(key2, new { a = "world" }) |
| 766 | + }; |
| 767 | + await commands.MSetAsync(values) |
| 768 | +; |
| 769 | + var result = await commands.MGetAsync(keys.Select(x => new RedisKey(x)).ToArray(), "$.a"); |
| 770 | + |
| 771 | + Assert.Equal("[\"hello\"]", result[0].ToString()); |
| 772 | + Assert.Equal("[\"world\"]", result[1].ToString()); |
| 773 | + |
| 774 | + // test errors: |
| 775 | + await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await commands.MSetAsync(new KeyValuePath[0])); |
| 776 | + } |
| 777 | + |
| 778 | + [Fact] |
| 779 | + public void TestKeyValuePathErrors() |
| 780 | + { |
| 781 | + Assert.Throws<ArgumentNullException>(() => new KeyValuePath(null!, new { a = "hello" })); |
| 782 | + Assert.Throws<ArgumentNullException>(() => new KeyValuePath("key", null!) ); |
| 783 | + } |
| 784 | + |
728 | 785 | [Fact] |
729 | 786 | public void MGet() |
730 | 787 | { |
|
0 commit comments