Skip to content

Commit 3c835f1

Browse files
authored
Creating CommandBuilders (#42)
* Creating ExecuteInTransaction function * test cpmmit * Add SerializedCommands & BloomSerializer * Creating ExecuteInTransaction function * test cpmmit * Add SerializedCommands & BloomSerializer * Fix SerializedCommand * Add CmsCommandBuilder * Naming * Add CuckooCommndBuilder * Add TdigestCommndBuilder * Add TopKCommandBuilder * Add JsonCommandBuilder * Add SearchCommandBuilder * Fix Tests * Add TimeSeriesCommandBuilder * Remove Unessesary using * Connecting GraphCommands to the documentation of the interface * Add GraphCommandBuilder * Update Version to 0.4.0 * Writing README * update words to ignore
1 parent 55fe3d6 commit 3c835f1

24 files changed

+1647
-1469
lines changed

Diff for: .github/wordlist.txt

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ github
44
yml
55
Codecov
66
pre
7+
OSS
8+
Json
9+
json
10+
TimeSeries
11+
NuGet

Diff for: README.md

+49
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,52 @@ This project builds on [StackExchange.Redis](https://github.com/StackExchange/St
1414
## API
1515

1616
The complete documentation for Redis module commands can be found at the [Redis commands website](https://redis.io/commands/).
17+
18+
### Redis OSS commands
19+
You can use Redis OSS commands in the same way as you use them in [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis).
20+
21+
### Modules Commands
22+
Each module has a command class with its own commands.
23+
The supported modules are: [Search](https://redis.io/commands/?group=search), [Json](https://redis.io/commands/?group=json), [Graph](https://redis.io/commands/?group=graph), [TimeSeries](https://redis.io/commands/?group=timeseries), [Bloom Filter](https://redis.io/commands/?group=bf), [Cuckoo Filter](https://redis.io/commands/?group=cf), [T-Digest](https://redis.io/commands/?group=tdigest), [Count-min Sketch](https://redis.io/commands/?group=cms) and [Top-K](https://redis.io/commands/?group=topk).
24+
25+
# Usage
26+
27+
First, you need to connect to Redis, exactly the same way you do it in [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis):
28+
```csharp
29+
using StackExchange.Redis;
30+
...
31+
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
32+
```
33+
Now you can create a variable from any type of module in the following way:
34+
```csharp
35+
IBloomCommands bf = db.BF();
36+
ICuckooCommands cf = db.CF();
37+
ICmsCommands cms = db.CMS();
38+
IGraphCommands graph = db.GRAPH();
39+
ITopKCommands topk = db.TOPK();
40+
ITdigestCommands tdigest = db.TDIGEST();
41+
ISearchCommands ft = db.FT();
42+
IJsonCommands json = db.JSON();
43+
ITimeSeriesCommands ts = db.TS();
44+
```
45+
Then, that variable will allow you to call all the commands of that module.
46+
## Basic Example
47+
Set a json object to Redis:
48+
```csharp
49+
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
50+
IDatabase db = redis.GetDatabase();
51+
52+
IJsonCommands json = db.JSON();
53+
var key = "myKey";
54+
json.Set(key, "$", new Person() { Age = 35, Name = "Alice" });
55+
```
56+
57+
------
58+
59+
### Author
60+
61+
NRedisStack is developed and maintained by [Redis Inc](https://redis.com). It can be found [here](
62+
https://github.com/redis/NRedisStack), or downloaded from [NuGet](https://www.nuget.org/packages/NRedisStack).
63+
64+
[![Redis](./docs/logo-redis.png)](https://www.redis.com)
65+

Diff for: src/NRedisStack/Auxiliary.cs

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NRedisStack.RedisStackCommands;
12
using StackExchange.Redis;
23

34
namespace NRedisStack
@@ -24,5 +25,15 @@ public static object[] AssembleNonNullArguments(params object?[] arguments)
2425

2526
return args.ToArray();
2627
}
28+
29+
public static RedisResult Execute(this IDatabase db, SerializedCommand command)
30+
{
31+
return db.Execute(command.Command, command.Args);
32+
}
33+
34+
public async static Task<RedisResult> ExecuteAsync(this IDatabase db, SerializedCommand command)
35+
{
36+
return await db.ExecuteAsync(command.Command, command.Args);
37+
}
2738
}
2839
}

Diff for: src/NRedisStack/Bloom/BloomCommandBuilder.cs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using NRedisStack.Literals;
2+
using NRedisStack.RedisStackCommands;
3+
using StackExchange.Redis;
4+
namespace NRedisStack
5+
{
6+
7+
public static class BloomCommandBuilder
8+
{
9+
public static SerializedCommand Add(RedisKey key, RedisValue item)
10+
{
11+
return new SerializedCommand(BF.ADD, key, item);
12+
}
13+
14+
public static SerializedCommand Exists(RedisKey key, RedisValue item)
15+
{
16+
return new SerializedCommand(BF.EXISTS, key, item);
17+
}
18+
19+
public static SerializedCommand Info(RedisKey key)
20+
{
21+
return new SerializedCommand(BF.INFO, key);
22+
}
23+
24+
public static SerializedCommand Insert(RedisKey key, RedisValue[] items, int? capacity = null,
25+
double? error = null, int? expansion = null,
26+
bool nocreate = false, bool nonscaling = false)
27+
{
28+
if (items.Length < 1)
29+
throw new ArgumentOutOfRangeException(nameof(items));
30+
31+
var args = BloomAux.BuildInsertArgs(key, items, capacity, error, expansion, nocreate, nonscaling);
32+
33+
return new SerializedCommand(BF.INSERT, args);
34+
}
35+
36+
public static SerializedCommand LoadChunk(RedisKey key, long iterator, Byte[] data)
37+
{
38+
return new SerializedCommand(BF.LOADCHUNK, key, iterator, data);
39+
}
40+
41+
public static SerializedCommand MAdd(RedisKey key, params RedisValue[] items)
42+
{
43+
if (items.Length < 1)
44+
throw new ArgumentOutOfRangeException(nameof(items));
45+
46+
List<object> args = new List<object> { key };
47+
48+
foreach (var item in items)
49+
{
50+
args.Add(item);
51+
}
52+
53+
return new SerializedCommand(BF.MADD, args);
54+
}
55+
56+
public static SerializedCommand MExists(RedisKey key, RedisValue[] items)
57+
{
58+
if (items.Length < 1)
59+
throw new ArgumentOutOfRangeException(nameof(items));
60+
61+
List<object> args = new List<object> { key };
62+
63+
foreach (var item in items)
64+
{
65+
args.Add(item);
66+
}
67+
68+
return new SerializedCommand(BF.MEXISTS, args);
69+
70+
}
71+
72+
public static SerializedCommand Reserve(RedisKey key, double errorRate, long capacity,
73+
int? expansion = null, bool nonscaling = false)
74+
{
75+
List<object> args = new List<object> { key, errorRate, capacity };
76+
77+
if (expansion != null)
78+
{
79+
args.Add(expansion);
80+
}
81+
82+
if (nonscaling)
83+
{
84+
args.Add(BloomArgs.NONSCALING);
85+
}
86+
87+
return new SerializedCommand(BF.RESERVE, args);
88+
}
89+
90+
public static SerializedCommand ScanDump(RedisKey key, long iterator)
91+
{
92+
return new SerializedCommand(BF.SCANDUMP, key, iterator);
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)