Skip to content

Commit b901d6a

Browse files
authored
Merge pull request #4 from shacharPash/AddModuls
Add moduls
2 parents d573c6c + 3e29443 commit b901d6a

25 files changed

+1111
-90
lines changed
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
using StackExchange.Redis;
2-
namespace NRedisStack.Core.RedisStackCommands
2+
namespace NRedisStack.Core
33
{
4-
public static class RedisBloomCommands
4+
5+
public class BloomCommands
56
{
6-
public static RedisResult BfAdd(this IDatabase db, RedisKey key, string item)
7+
IDatabase _db;
8+
public BloomCommands(IDatabase db)
79
{
8-
return db.Execute("BF.ADD", key, item);
10+
_db = db;
911
}
10-
public static RedisResult BfExists(this IDatabase db, RedisKey key, string item)
12+
13+
14+
public RedisResult Add(RedisKey key, string item)
1115
{
12-
return db.Execute("BF.EXISTS", key, item);
16+
return _db.Execute("BF.ADD", key, item);
17+
}
18+
public RedisResult Exists(RedisKey key, string item)
19+
{
20+
return _db.Execute("BF.EXISTS", key, item);
1321
}
1422
/*public static string ADD => "BF.ADD";
1523
public static string EXISTS => "BF.EXISTS";
@@ -21,4 +29,6 @@ public static RedisResult BfExists(this IDatabase db, RedisKey key, string item)
2129
public static string RESERVE => "BF.RESERVE";
2230
public static string SCANDUMP => "BF.SCANDUMP";*/
2331
}
24-
}
32+
33+
34+
}

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,39 @@
22
using System.Text.Json;
33
using System.Text.Json.Serialization;
44

5-
namespace NRedisStack.Core.Json;
5+
namespace NRedisStack.Core;
66

7-
public static class JSON
7+
public class JsonCommands
88
{
9-
private static readonly JsonSerializerOptions Options = new()
9+
IDatabase _db;
10+
public JsonCommands(IDatabase db)
11+
{
12+
_db = db;
13+
}
14+
private readonly JsonSerializerOptions Options = new()
1015
{
1116
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
1217
};
13-
public static RedisResult JsonSet(this IDatabase db, RedisKey key, string path, object obj, When when = When.Always)
18+
public RedisResult Set(RedisKey key, string path, object obj, When when = When.Always)
1419
{
1520
string json = JsonSerializer.Serialize(obj);
16-
return JsonSet(db, key, path, json, when);
21+
return Set(key, path, json, when);
1722
}
1823

19-
public static RedisResult JsonSet(this IDatabase db, RedisKey key, string path, string json, When when = When.Always)
24+
public RedisResult Set(RedisKey key, string path, string json, When when = When.Always)
2025
{
2126
switch (when)
2227
{
2328
case When.Exists:
24-
return db.Execute("JSON.SET", key, path, json, "XX");
29+
return _db.Execute("JSON.SET", key, path, json, "XX");
2530
case When.NotExists:
26-
return db.Execute("JSON.SET", key, path, json, "NX");
31+
return _db.Execute("JSON.SET", key, path, json, "NX");
2732
default:
28-
return db.Execute("JSON.SET", key, path, json);
33+
return _db.Execute("JSON.SET", key, path, json);
2934
}
3035
}
3136

32-
public static RedisResult JsonGet(this IDatabase db, RedisKey key, string indent = "",
37+
public RedisResult Get(RedisKey key, string indent = "",
3338
string newLine = "", string space = "", string path = "")
3439
{
3540
List<object> subcommands = new List<object>();
@@ -56,6 +61,6 @@ public static RedisResult JsonGet(this IDatabase db, RedisKey key, string indent
5661
{
5762
subcommands.Add(path);
5863
}
59-
return db.Execute("JSON.GET", subcommands.ToArray());
64+
return _db.Execute("JSON.GET", subcommands.ToArray());
6065
}
6166
}

src/NRedisStack.Core/ModulPrefixes.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using StackExchange.Redis;
2+
3+
namespace NRedisStack.Core.RedisStackCommands
4+
{
5+
public static class ModulPrefixes
6+
{
7+
static public BloomCommands BF(this IDatabase db)
8+
{
9+
return new BloomCommands(db);
10+
}
11+
12+
static public SearchCommands FT(this IDatabase db)
13+
{
14+
return new SearchCommands(db);
15+
}
16+
17+
static public JsonCommands JSON(this IDatabase db)
18+
{
19+
return new JsonCommands(db);
20+
}
21+
22+
static public TimeSeriesCommands TS(this IDatabase db)
23+
{
24+
return new TimeSeriesCommands(db);
25+
}
26+
}
27+
}

src/NRedisStack.Core/RedisStackCommands/Search.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using StackExchange.Redis;
2+
namespace NRedisStack.Core
3+
{
4+
public class SearchCommands
5+
{
6+
IDatabase _db;
7+
public SearchCommands(IDatabase db)
8+
{
9+
_db = db;
10+
}
11+
public RedisResult FtInfo(string index)
12+
{
13+
return _db.Execute("FT.INFO", index);
14+
}
15+
}
16+
}

src/NRedisStack.Core/TimeSeries/Commands/CommandArgs.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace NRedisStack.Core.TimeSeries.Commands
1+
namespace NRedisStack.Core.Commands
22
{
33
internal class CommandArgs
44
{
@@ -19,5 +19,6 @@ internal class CommandArgs
1919
public static string REDUCE => "REDUCE";
2020
public static string FILTER_BY_TS => "FILTER_BY_TS";
2121
public static string FILTER_BY_VALUE => "FILTER_BY_VALUE";
22+
2223
}
23-
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
namespace NRedisStack.Core.RedisStackCommands
1+
namespace NRedisStack.Core.Commands
22
{
3-
public static class TS
3+
internal class TS
44
{
5-
6-
//TODO: INFO, CREATE, ALTER
7-
/*public static string CREATE => "TS.CREATE";
5+
public static string CREATE => "TS.CREATE";
86
public static string ALTER => "TS.ALTER";
97
public static string ADD => "TS.ADD";
108
public static string MADD => "TS.MADD";
119
public static string INCRBY => "TS.INCRBY";
1210
public static string DECRBY => "TS.DECRBY";
11+
public static string DEL => "TS.DEL";
1312
public static string CREATERULE => "TS.CREATERULE";
1413
public static string DELETERULE => "TS.DELETERULE";
1514
public static string RANGE => "TS.RANGE";
@@ -19,6 +18,6 @@ public static class TS
1918
public static string GET => "TS.GET";
2019
public static string MGET => "TS.MGET";
2120
public static string INFO => "TS.INFO";
22-
public static string QUERYINDEX => "TS.QUERYINDEX";*/
21+
public static string QUERYINDEX => "TS.QUERYINDEX";
2322
}
24-
}
23+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace NRedisStack.Core.Commands.Enums
2+
{
3+
/// <summary>
4+
/// An aggregation type to be used with a time bucket.
5+
/// </summary>
6+
public enum TsAggregation
7+
{
8+
/// <summary>
9+
/// The average of all samples in the aggregation
10+
/// </summary>
11+
Avg,
12+
13+
/// <summary>
14+
/// A sum of all samples in the aggregation
15+
/// </summary>
16+
Sum,
17+
18+
/// <summary>
19+
/// A minimum sample of all samples in the aggregation
20+
/// </summary>
21+
Min,
22+
23+
/// <summary>
24+
/// A maximum sample of all samples in the aggregation
25+
/// </summary>
26+
Max,
27+
28+
/// <summary>
29+
/// A range of the min and max sample of all samples in the aggregation (range r = max-min)
30+
/// For example if the min sample was 100 and the max was 400, the range aggregation would return 300
31+
/// </summary>
32+
Range,
33+
34+
/// <summary>
35+
/// The total number of all samples in the aggregation
36+
/// </summary>
37+
Count,
38+
39+
/// <summary>
40+
/// The first sample in the aggregation
41+
/// </summary>
42+
First,
43+
44+
/// <summary>
45+
/// The last sample in the aggregation
46+
/// </summary>
47+
Last,
48+
49+
/// <summary>
50+
/// The standard deviation based on the entire population
51+
/// The standard deviation is a measure of how widely values are dispersed from the average sample in the aggregation
52+
/// </summary>
53+
StdP,
54+
55+
/// <summary>
56+
/// The standard deviation based on a sample of the population
57+
/// The standard deviation is a measure of how widely values are dispersed from the average sample in the aggregation
58+
/// </summary>
59+
StdS,
60+
61+
/// <summary>
62+
/// The variance based on the entire population
63+
/// The variance is the average of the squared differences from the mean
64+
/// </summary>
65+
VarP,
66+
67+
/// <summary>
68+
/// The variance based on a sample of the population
69+
/// The variance is the average of the squared differences from the mean
70+
/// </summary>
71+
VarS,
72+
}
73+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace NRedisStack.Core.Commands.Enums
2+
{
3+
/// <summary>
4+
/// Policy to handle duplicate samples.
5+
/// The default policy for database-wide is BLOCK.
6+
/// </summary>
7+
public enum TsDuplicatePolicy
8+
{
9+
/// <summary>
10+
/// An error will occur for any out of order sample.
11+
/// </summary>
12+
BLOCK,
13+
14+
/// <summary>
15+
/// Ignore the new value.
16+
/// </summary>
17+
FIRST,
18+
19+
/// <summary>
20+
/// Override with latest value.
21+
/// </summary>
22+
LAST,
23+
24+
/// <summary>
25+
/// Only override if the value is lower than the existing value.
26+
/// </summary>
27+
MIN,
28+
29+
/// <summary>
30+
/// Only override if the value is higher than the existing value.
31+
/// </summary>
32+
MAX,
33+
34+
/// <summary>
35+
/// If a previous sample exists, add the new sample to it so that the updated value is equal to (previous + new).
36+
/// If no previous sample exists, set the updated value equal to the new value.
37+
/// </summary>
38+
SUM
39+
}
40+
}
41+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace NRedisStack.Core.Commands.Enums
2+
{
3+
/// <summary>
4+
/// TODO: Add description
5+
/// </summary>
6+
public enum TsReduce
7+
{
8+
/// <summary>
9+
/// A sum of all samples in the group
10+
/// </summary>
11+
Sum,
12+
13+
/// <summary>
14+
/// A minimum sample of all samples in the group
15+
/// </summary>
16+
Min,
17+
18+
/// <summary>
19+
/// A maximum sample of all samples in the group
20+
/// </summary>
21+
Max,
22+
}
23+
}

0 commit comments

Comments
 (0)