Skip to content

Commit f94c332

Browse files
authored
Merge pull request #5 from shacharPash/AddFeatures
-Add features -Add RedisBloom functions
2 parents cdf7dd7 + 1a5f025 commit f94c332

File tree

12 files changed

+195
-46
lines changed

12 files changed

+195
-46
lines changed
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NRedisStack.Core.Literals;
12
using StackExchange.Redis;
23
namespace NRedisStack.Core
34
{
@@ -10,25 +11,35 @@ public BloomCommands(IDatabase db)
1011
_db = db;
1112
}
1213

13-
1414
public RedisResult Add(RedisKey key, string item)
1515
{
16-
return _db.Execute("BF.ADD", key, item);
16+
return _db.Execute(BF.ADD, key, item);
1717
}
18+
1819
public RedisResult Exists(RedisKey key, string item)
1920
{
20-
return _db.Execute("BF.EXISTS", key, item);
21+
return _db.Execute(BF.EXISTS, key, item);
22+
}
23+
24+
public RedisResult Info(RedisKey key)
25+
{
26+
return _db.Execute(BF.INFO, key);
2127
}
22-
/*public static string ADD => "BF.ADD";
23-
public static string EXISTS => "BF.EXISTS";
24-
public static string INFO => "BF.INFO";
25-
public static string INSERT => "BF.INSERT";
26-
public static string LOADCHUNK => "BF.LOADCHUNK";
27-
public static string MADD => "BF.MADD";
28-
public static string MEXISTS => "BF.MEXISTS";
29-
public static string RESERVE => "BF.RESERVE";
30-
public static string SCANDUMP => "BF.SCANDUMP";*/
31-
}
3228

29+
public RedisResult Insert(RedisKey key)
30+
{
31+
return _db.Execute(BF.INFO, key);
32+
}
3333

34+
public RedisResult ScanDump(RedisKey key, int iterator)
35+
{
36+
return _db.Execute(BF.SCANDUMP, key, iterator);
37+
}
38+
39+
public RedisResult LoadChunk(RedisKey key, int iterator, string data)
40+
{
41+
return _db.Execute(BF.INFO, key, iterator, data);
42+
}
43+
44+
}
3445
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace NRedisStack.Core.Literals
2+
{
3+
internal class BloomArgs
4+
{
5+
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace NRedisStack.Core.Literals
2+
{
3+
internal class BF
4+
{
5+
public static string ADD => "BF.ADD";
6+
public static string EXISTS => "BF.EXISTS";
7+
public static string INFO => "BF.INFO";
8+
public static string INSERT => "BF.INSERT";
9+
public static string LOADCHUNK => "BF.LOADCHUNK";
10+
public static string MADD => "BF.MADD";
11+
public static string MEXISTS => "BF.MEXISTS";
12+
public static string RESERVE => "BF.RESERVE";
13+
public static string SCANDUMP => "BF.SCANDUMP";
14+
}
15+
}

src/NRedisStack.Core/Json/JsonCommands.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using StackExchange.Redis;
1+
using NRedisStack.Core.Literals;
2+
using StackExchange.Redis;
23
using System.Text.Json;
34
using System.Text.Json.Serialization;
45

@@ -26,11 +27,11 @@ public RedisResult Set(RedisKey key, string path, string json, When when = When.
2627
switch (when)
2728
{
2829
case When.Exists:
29-
return _db.Execute("JSON.SET", key, path, json, "XX");
30+
return _db.Execute(JSON.SET, key, path, json, "XX");
3031
case When.NotExists:
31-
return _db.Execute("JSON.SET", key, path, json, "NX");
32+
return _db.Execute(JSON.SET, key, path, json, "NX");
3233
default:
33-
return _db.Execute("JSON.SET", key, path, json);
34+
return _db.Execute(JSON.SET, key, path, json);
3435
}
3536
}
3637

@@ -41,26 +42,26 @@ public RedisResult Get(RedisKey key, string indent = "",
4142
subcommands.Add(key);
4243
if (indent != "")
4344
{
44-
subcommands.Add("INDENT");
45+
subcommands.Add(JsonArgs.INDENT);
4546
subcommands.Add(indent);
4647
}
4748

4849
if (newLine != "")
4950
{
50-
subcommands.Add("NEWLINE");
51+
subcommands.Add(JsonArgs.NEWLINE);
5152
subcommands.Add(newLine);
5253
}
5354

5455
if (space != "")
5556
{
56-
subcommands.Add("SPACE");
57+
subcommands.Add(JsonArgs.SPACE);
5758
subcommands.Add(space);
5859
}
5960

6061
if (path != "")
6162
{
6263
subcommands.Add(path);
6364
}
64-
return _db.Execute("JSON.GET", subcommands.ToArray());
65+
return _db.Execute(JSON.GET, subcommands.ToArray());
6566
}
6667
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace NRedisStack.Core.Literals
2+
{
3+
internal class JsonArgs
4+
{
5+
public static string INDENT => "INDENT";
6+
public static string NEWLINE => "NEWLINE";
7+
public static string SPACE => "SPACE";
8+
9+
}
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace NRedisStack.Core.Literals
2+
{
3+
internal class JSON
4+
{
5+
public static string ARRAPPEND => "JSON.ARRAPPEND";
6+
public static string ARRINDEX => "JSON.ARRINDEX";
7+
public static string ARRINSERT => "JSON.ARRINSERT";
8+
public static string ARRLEN => "JSON.ARRLEN";
9+
public static string ARRPOP => "JSON.ARRPOP";
10+
public static string ARRTRIM => "JSON.ARRTRIM";
11+
public static string CLEAR => "JSON.CLEAR";
12+
public static string DEBUG => "JSON.DEBUG";
13+
public static string DEBUG_HELP => "JSON.DEBUG HELP";
14+
public static string DEBUG_MEMORY => "JSON.DEBUG MEMORY";
15+
public static string DEL => "JSON.DEL";
16+
public static string FORGET => "JSON.FORGET";
17+
public static string GET => "JSON.GET";
18+
public static string MGET => "JSON.MGET";
19+
public static string NUMINCRBY => "JSON.NUMINCRBY";
20+
public static string NUMMULTBY => "JSON.NUMMULTBY";
21+
public static string OBJKEYS => "JSON.OBJKEYS";
22+
public static string OBJLEN => "JSON.OBJLEN";
23+
public static string RESP => "JSON.RESP";
24+
public static string SET => "JSON.SET";
25+
public static string STRAPPEND => "JSON.STRAPPEND";
26+
public static string STRLEN => "JSON.STRLEN";
27+
public static string TOGGLE => "JSON.TOGGLE";
28+
public static string TYPE => "JSON.TYPE";
29+
}
30+
}

src/NRedisStack.Core/ModulPrefixes.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,60 @@ namespace NRedisStack.Core.RedisStackCommands
44
{
55
public static class ModulPrefixes
66
{
7+
static bool bloomCreated = false;
8+
static BloomCommands bloomCommands;
9+
10+
static bool searchCreated = false;
11+
static SearchCommands searchCommands;
12+
13+
static bool jsonCreated = false;
14+
static JsonCommands jsonCommands;
15+
16+
static bool timeSeriesCreated = false;
17+
static TimeSeriesCommands timeSeriesCommands;
18+
719
static public BloomCommands BF(this IDatabase db)
820
{
9-
return new BloomCommands(db);
21+
if (!bloomCreated)
22+
{
23+
bloomCommands = new BloomCommands(db);
24+
bloomCreated = true;
25+
}
26+
27+
return bloomCommands;
1028
}
1129

1230
static public SearchCommands FT(this IDatabase db)
1331
{
14-
return new SearchCommands(db);
32+
if (!searchCreated)
33+
{
34+
searchCommands = new SearchCommands(db);
35+
searchCreated = true;
36+
}
37+
38+
return searchCommands;
1539
}
1640

1741
static public JsonCommands JSON(this IDatabase db)
1842
{
19-
return new JsonCommands(db);
43+
if (!jsonCreated)
44+
{
45+
jsonCommands = new JsonCommands(db);
46+
jsonCreated = true;
47+
}
48+
49+
return jsonCommands;
2050
}
2151

2252
static public TimeSeriesCommands TS(this IDatabase db)
2353
{
24-
return new TimeSeriesCommands(db);
54+
if (!jsonCreated)
55+
{
56+
timeSeriesCommands = new TimeSeriesCommands(db);
57+
timeSeriesCreated = true;
58+
}
59+
60+
return timeSeriesCommands;
2561
}
2662
}
2763
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace NRedisStack.Core.Literals
2+
{
3+
internal class SearchArgs
4+
{
5+
6+
}
7+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace NRedisStack.Core.Literals
2+
{
3+
internal class FT
4+
{
5+
public static string _LIST => "FT._LIST";
6+
public static string AGGREGATE => "FT.AGGREGATE";
7+
public static string ALIASADD => "FT.ALIASADD";
8+
public static string ALIASDEL => "FT.ALIASDEL";
9+
public static string ALIASUPDATE => "FT.ALIASUPDATE";
10+
public static string ALTER => "FT.ALTER";
11+
public static string CONFIG_GET => "FT.CONFIG GET";
12+
public static string CONFIG_HELP => "FT.CONFIG HELP";
13+
public static string CONFIG_SET => "FT.CONFIG SET";
14+
public static string CREATE => "FT.CREATE";
15+
public static string CURSOR_DEL => "FT.CURSOR DEL";
16+
public static string CURSOR_READ => "FT.CURSOR READ";
17+
public static string DICTADD => "FT.DICTADD";
18+
public static string DICTDEL => "FT.DICTDEL";
19+
public static string DICTDUMP => "FT.DICTDUMP";
20+
public static string DROPINDEX => "FT.DROPINDEX";
21+
public static string EXPLAIN => "FT.EXPLAIN";
22+
public static string EXPLAINCLI => "FT.EXPLAINCLI";
23+
public static string INFO => "FT.INFO";
24+
public static string PROFILE => "FT.PROFILE";
25+
public static string SEARCH => "FT.SEARCH";
26+
public static string SPELLCHECK => "FT.SPELLCHECK";
27+
public static string SYNDUMP => "FT.SYNDUMP";
28+
public static string SYNUPDATE => "FT.SYNUPDATE";
29+
public static string TAGVALS => "FT.TAGVALS";
30+
}
31+
}

src/NRedisStack.Core/Search/SearchCommands.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NRedisStack.Core.Literals;
12
using StackExchange.Redis;
23
namespace NRedisStack.Core
34
{
@@ -8,9 +9,9 @@ public SearchCommands(IDatabase db)
89
{
910
_db = db;
1011
}
11-
public RedisResult FtInfo(string index)
12+
public RedisResult Info(string index)
1213
{
13-
return _db.Execute("FT.INFO", index);
14+
return _db.Execute(FT.INFO, index);
1415
}
1516
}
1617
}

0 commit comments

Comments
 (0)