Skip to content

Commit 1a5f025

Browse files
committed
Add RedisBloom commands & Verify the creation of only one instance of each commands class
1 parent 9d404cd commit 1a5f025

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

src/NRedisStack.Core/Bloom/BloomCommands.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,35 @@ public BloomCommands(IDatabase db)
1111
_db = db;
1212
}
1313

14-
1514
public RedisResult Add(RedisKey key, string item)
1615
{
1716
return _db.Execute(BF.ADD, key, item);
1817
}
18+
1919
public RedisResult Exists(RedisKey key, string item)
2020
{
2121
return _db.Execute(BF.EXISTS, key, item);
2222
}
2323

24+
public RedisResult Info(RedisKey key)
25+
{
26+
return _db.Execute(BF.INFO, key);
27+
}
28+
29+
public RedisResult Insert(RedisKey key)
30+
{
31+
return _db.Execute(BF.INFO, key);
32+
}
33+
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+
2444
}
2545
}

src/NRedisStack.Core/ModulPrefixes.cs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,60 @@ namespace NRedisStack.Core.RedisStackCommands
44
{
55
public static class ModulPrefixes
66
{
7-
// Every call, new instance is being created. need to be fix
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+
819
static public BloomCommands BF(this IDatabase db)
920
{
10-
return new BloomCommands(db);
21+
if (!bloomCreated)
22+
{
23+
bloomCommands = new BloomCommands(db);
24+
bloomCreated = true;
25+
}
26+
27+
return bloomCommands;
1128
}
1229

1330
static public SearchCommands FT(this IDatabase db)
1431
{
15-
return new SearchCommands(db);
32+
if (!searchCreated)
33+
{
34+
searchCommands = new SearchCommands(db);
35+
searchCreated = true;
36+
}
37+
38+
return searchCommands;
1639
}
1740

1841
static public JsonCommands JSON(this IDatabase db)
1942
{
20-
return new JsonCommands(db);
43+
if (!jsonCreated)
44+
{
45+
jsonCommands = new JsonCommands(db);
46+
jsonCreated = true;
47+
}
48+
49+
return jsonCommands;
2150
}
2251

2352
static public TimeSeriesCommands TS(this IDatabase db)
2453
{
25-
return new TimeSeriesCommands(db);
54+
if (!jsonCreated)
55+
{
56+
timeSeriesCommands = new TimeSeriesCommands(db);
57+
timeSeriesCreated = true;
58+
}
59+
60+
return timeSeriesCommands;
2661
}
2762
}
2863
}

0 commit comments

Comments
 (0)