Skip to content

Commit d573c6c

Browse files
authored
Merge pull request #3 from shacharPash/AddModuls
Add basic command in each module & Arrange the files in folders
2 parents 5e510fa + cf50d69 commit d573c6c

File tree

10 files changed

+155
-32
lines changed

10 files changed

+155
-32
lines changed

src/NRedisStack.Core/Bloom/RedisBloomCommands.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace NRedisStack.Core.RedisStackCommands
2+
{
3+
public static class TS
4+
{
5+
6+
//TODO: INFO, CREATE, ALTER
7+
/*public static string CREATE => "TS.CREATE";
8+
public static string ALTER => "TS.ALTER";
9+
public static string ADD => "TS.ADD";
10+
public static string MADD => "TS.MADD";
11+
public static string INCRBY => "TS.INCRBY";
12+
public static string DECRBY => "TS.DECRBY";
13+
public static string CREATERULE => "TS.CREATERULE";
14+
public static string DELETERULE => "TS.DELETERULE";
15+
public static string RANGE => "TS.RANGE";
16+
public static string REVRANGE => "TS.REVRANGE";
17+
public static string MRANGE => "TS.MRANGE";
18+
public static string MREVRANGE => "TS.MREVRANGE";
19+
public static string GET => "TS.GET";
20+
public static string MGET => "TS.MGET";
21+
public static string INFO => "TS.INFO";
22+
public static string QUERYINDEX => "TS.QUERYINDEX";*/
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using StackExchange.Redis;
2+
namespace NRedisStack.Core.RedisStackCommands
3+
{
4+
public static class RedisBloomCommands
5+
{
6+
public static RedisResult BfAdd(this IDatabase db, RedisKey key, string item)
7+
{
8+
return db.Execute("BF.ADD", key, item);
9+
}
10+
public static RedisResult BfExists(this IDatabase db, RedisKey key, string item)
11+
{
12+
return db.Execute("BF.EXISTS", key, item);
13+
}
14+
/*public static string ADD => "BF.ADD";
15+
public static string EXISTS => "BF.EXISTS";
16+
public static string INFO => "BF.INFO";
17+
public static string INSERT => "BF.INSERT";
18+
public static string LOADCHUNK => "BF.LOADCHUNK";
19+
public static string MADD => "BF.MADD";
20+
public static string MEXISTS => "BF.MEXISTS";
21+
public static string RESERVE => "BF.RESERVE";
22+
public static string SCANDUMP => "BF.SCANDUMP";*/
23+
}
24+
}

src/NRedisStack.Core/Json/RedisJsonCommands.cs renamed to src/NRedisStack.Core/RedisStackCommands/Json.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using StackExchange.Redis;
22
using System.Text.Json;
33
using System.Text.Json.Serialization;
4+
45
namespace NRedisStack.Core.Json;
56

6-
public static class RedisJsonCommands
7+
public static class JSON
78
{
89
private static readonly JsonSerializerOptions Options = new()
910
{
@@ -17,7 +18,7 @@ public static RedisResult JsonSet(this IDatabase db, RedisKey key, string path,
1718

1819
public static RedisResult JsonSet(this IDatabase db, RedisKey key, string path, string json, When when = When.Always)
1920
{
20-
switch(when)
21+
switch (when)
2122
{
2223
case When.Exists:
2324
return db.Execute("JSON.SET", key, path, json, "XX");
@@ -28,8 +29,33 @@ public static RedisResult JsonSet(this IDatabase db, RedisKey key, string path,
2829
}
2930
}
3031

31-
public static RedisResult JsonGet(this IDatabase db, RedisKey key)
32+
public static RedisResult JsonGet(this IDatabase db, RedisKey key, string indent = "",
33+
string newLine = "", string space = "", string path = "")
3234
{
33-
return db.Execute("JSON.GET", key);
35+
List<object> subcommands = new List<object>();
36+
subcommands.Add(key);
37+
if (indent != "")
38+
{
39+
subcommands.Add("INDENT");
40+
subcommands.Add(indent);
41+
}
42+
43+
if (newLine != "")
44+
{
45+
subcommands.Add("NEWLINE");
46+
subcommands.Add(newLine);
47+
}
48+
49+
if (space != "")
50+
{
51+
subcommands.Add("SPACE");
52+
subcommands.Add(space);
53+
}
54+
55+
if (path != "")
56+
{
57+
subcommands.Add(path);
58+
}
59+
return db.Execute("JSON.GET", subcommands.ToArray());
3460
}
3561
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using StackExchange.Redis;
2+
namespace NRedisStack.Core.Search
3+
{
4+
public static class FT
5+
{
6+
public static RedisResult FtInfo(this IDatabase db, string index)
7+
{
8+
return db.Execute("FT.INFO", index);
9+
}
10+
}
11+
}

src/NRedisStack.Core/Search/RedisSearchCommands.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/NRedisStack.Core/TimeSeries/TimeSeriesCommands.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Xunit;
2+
using System;
3+
using System.Collections.Generic;
4+
using StackExchange.Redis;
5+
using System.Linq;
6+
using System.IO;
7+
using NRedisStack.Core;
8+
using NRedisStack.Core.RedisStackCommands;
9+
using Moq;
10+
11+
using System.Text.Json;
12+
using System.Text.Json.Serialization;
13+
14+
15+
namespace NRedisStack.Tests.Bloom;
16+
17+
public class BloomTests : AbstractNRedisStackTest, IDisposable
18+
{
19+
Mock<IDatabase> _mock = new Mock<IDatabase>();
20+
private readonly string key = "BLOOM_TESTS";
21+
public BloomTests(RedisFixture redisFixture) : base(redisFixture) { }
22+
23+
public void Dispose()
24+
{
25+
redisFixture.Redis.GetDatabase().KeyDelete(key);
26+
}
27+
28+
[Fact]
29+
public void TestBfAddWhenExist()
30+
{
31+
IDatabase db = redisFixture.Redis.GetDatabase();
32+
33+
Assert.True(db.BfAdd(key, "item1").ToString() == "1"); // first time
34+
Assert.True(db.BfAdd(key, "item1").ToString() == "0"); // second time
35+
}
36+
37+
[Fact]
38+
public void TestBfAddExists()
39+
{
40+
IDatabase db = redisFixture.Redis.GetDatabase();
41+
42+
db.BfAdd(key, "item1");
43+
Assert.True(db.BfExists(key, "item1").ToString() == "1");
44+
}
45+
}

tests/NRedisStack.Tests/JsonTests.cs renamed to tests/NRedisStack.Tests/Json/JsonTests.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ public void Dispose()
2525
redisFixture.Redis.GetDatabase().KeyDelete(key);
2626
}
2727

28-
public class Person
29-
{
30-
public string Name { get; set; }
31-
public int Age { get; set; }
32-
}
33-
3428
[Fact]
3529
public void TestJsonSet()
3630
{
@@ -48,7 +42,7 @@ public void TestJsonSetNotExist()
4842
}
4943

5044
[Fact]
51-
public void TestJsonGet()
45+
public void TestSimpleJsonGet()
5246
{
5347
var obj = new Person { Name = "Shachar", Age = 23 };
5448
IDatabase db = redisFixture.Redis.GetDatabase();
@@ -57,4 +51,16 @@ public void TestJsonGet()
5751
string expected = "{\"Name\":\"Shachar\",\"Age\":23}";
5852
Assert.Equal(db.JsonGet(key).ToString(), expected);
5953
}
54+
55+
[Fact]
56+
public void TestJsonGet()
57+
{
58+
var obj = new Person { Name = "Shachar", Age = 23 };
59+
IDatabase db = redisFixture.Redis.GetDatabase();
60+
61+
db.JsonSet(key, "$", obj);
62+
63+
string expected = "[222111\"Shachar\"222]";
64+
Assert.Equal(db.JsonGet(key, "111", "222", "333", "$.Name").ToString(), expected);
65+
}
6066
}

tests/NRedisStack.Tests/Person.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace NRedisStack.Tests
2+
{
3+
public class Person
4+
{
5+
public string Name { get; set; }
6+
public int Age { get; set; }
7+
}
8+
}

0 commit comments

Comments
 (0)