Skip to content

Commit eb26a9e

Browse files
authored
Start addin Tdigest commands (#8)
* Start addin Tdigest commands * Add Tdigest Commands & Fixing Parsing Warnings
1 parent 8fe55a6 commit eb26a9e

File tree

16 files changed

+705
-172
lines changed

16 files changed

+705
-172
lines changed

src/NRedisStack.Core/Auxiliary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace NRedisStack.Core
44
{
55
public static class Auxiliary
66
{
7-
public static List<object> MergeArgs(RedisKey key, RedisValue[] items)
7+
public static List<object> MergeArgs(RedisKey key, params RedisValue[] items)
88
{
99
var args = new List<object> { key };
1010
foreach (var item in items) args.Add(item);

src/NRedisStack.Core/Bloom/BloomCommands.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
7070
/// <param name="key">Name of the key to return information about.</param>
7171
/// <returns>Information of the filter.</returns>
7272
/// <remarks><seealso href="https://redis.io/commands/bf.info"/></remarks>
73-
public BloomInformation? Info(RedisKey key)
73+
public BloomInformation Info(RedisKey key)
7474
{
7575
var info = _db.Execute(BF.INFO, key);
7676
return ResponseParser.ToBloomInfo(info);
@@ -82,7 +82,7 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
8282
/// <param name="key">Name of the key to return information about.</param>
8383
/// <returns>Information of the filter.</returns>
8484
/// <remarks><seealso href="https://redis.io/commands/bf.info"/></remarks>
85-
public async Task<BloomInformation?> InfoAsync(RedisKey key)
85+
public async Task<BloomInformation> InfoAsync(RedisKey key)
8686
{
8787
var info = await _db.ExecuteAsync(BF.INFO, key);
8888
return ResponseParser.ToBloomInfo(info);
@@ -108,8 +108,8 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
108108
double? error = null, int? expansion = null,
109109
bool nocreate = false, bool nonscaling = false)
110110
{
111-
if (items == null)
112-
throw new ArgumentNullException(nameof(items));
111+
if (items.Length < 1)
112+
throw new ArgumentOutOfRangeException(nameof(items));
113113

114114
List<object> args = new List<object> { key };
115115

@@ -119,6 +119,7 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
119119
args.Add(capacity);
120120
}
121121

122+
122123
if (error != null)
123124
{
124125
args.Add(BloomArgs.ERROR);
@@ -171,8 +172,8 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
171172
double? error = null, int? expansion = null,
172173
bool nocreate = false, bool nonscaling = false)
173174
{
174-
if (items == null)
175-
throw new ArgumentNullException(nameof(items));
175+
if (items.Length < 1)
176+
throw new ArgumentOutOfRangeException(nameof(items));
176177

177178
List<object> args = new List<object> { key };
178179

@@ -221,11 +222,11 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
221222
/// <param name="key">Name of the key to restore.</param>
222223
/// <param name="iterator">Iterator value associated with data (returned by SCANDUMP).</param>
223224
/// <param name="data">Current data chunk (returned by SCANDUMP).</param>
224-
/// <returns>Array with information of the filter.</returns>
225+
/// <returns><see langword="true"/> if executed correctly, error otherwise/></returns>
225226
/// <remarks><seealso href="https://redis.io/commands/bf.loadchunk"/></remarks>
226227
public bool LoadChunk(RedisKey key, long iterator, Byte[] data)
227228
{
228-
return ResponseParser.ParseOKtoBoolean(_db.Execute(BF.LOADCHUNK, key, iterator, data));
229+
return ResponseParser.OKtoBoolean(_db.Execute(BF.LOADCHUNK, key, iterator, data));
229230
}
230231

231232
/// <summary>
@@ -234,12 +235,12 @@ public bool LoadChunk(RedisKey key, long iterator, Byte[] data)
234235
/// <param name="key">Name of the key to restore.</param>
235236
/// <param name="iterator">Iterator value associated with data (returned by SCANDUMP).</param>
236237
/// <param name="data">Current data chunk (returned by SCANDUMP).</param>
237-
/// <returns>Array with information of the filter.</returns>
238+
/// <returns><see langword="true"/> if executed correctly, error otherwise/></returns>
238239
/// <remarks><seealso href="https://redis.io/commands/bf.loadchunk"/></remarks>
239240
public async Task<bool> LoadChunkAsync(RedisKey key, long iterator, Byte[] data)
240241
{
241242
var result = await _db.ExecuteAsync(BF.LOADCHUNK, key, iterator, data);
242-
return ResponseParser.ParseOKtoBoolean(result);
243+
return ResponseParser.OKtoBoolean(result);
243244
}
244245

245246
/// <summary>
@@ -250,10 +251,10 @@ public async Task<bool> LoadChunkAsync(RedisKey key, long iterator, Byte[] data)
250251
/// <returns>An array of booleans. Each element is either true or false depending on whether the
251252
/// corresponding input element was newly added to the filter or may have previously existed.</returns>
252253
/// <remarks><seealso href="https://redis.io/commands/bf.madd"/></remarks>
253-
public bool[] MAdd(RedisKey key, RedisValue[] items)
254+
public bool[] MAdd(RedisKey key, params RedisValue[] items)
254255
{
255-
if (items == null)
256-
throw new ArgumentNullException(nameof(items));
256+
if (items.Length < 1)
257+
throw new ArgumentOutOfRangeException(nameof(items));
257258

258259
List<object> args = new List<object> { key };
259260

@@ -273,10 +274,10 @@ public bool[] MAdd(RedisKey key, RedisValue[] items)
273274
/// <returns>An array of booleans. Each element is either true or false depending on whether the
274275
/// corresponding input element was newly added to the filter or may have previously existed.</returns>
275276
/// <remarks><seealso href="https://redis.io/commands/bf.madd"/></remarks>
276-
public async Task<bool[]> MAddAsync(RedisKey key, RedisValue[] items)
277+
public async Task<bool[]> MAddAsync(RedisKey key, params RedisValue[] items)
277278
{
278-
if (items == null)
279-
throw new ArgumentNullException(nameof(items));
279+
if (items.Length < 1)
280+
throw new ArgumentOutOfRangeException(nameof(items));
280281

281282
List<object> args = new List<object> { key };
282283

@@ -299,8 +300,8 @@ public async Task<bool[]> MAddAsync(RedisKey key, RedisValue[] items)
299300
/// <remarks><seealso href="https://redis.io/commands/bf.mexists"/></remarks>
300301
public bool[] MExists(RedisKey key, RedisValue[] items)
301302
{
302-
if (items == null)
303-
throw new ArgumentNullException(nameof(items));
303+
if (items.Length < 1)
304+
throw new ArgumentOutOfRangeException(nameof(items));
304305

305306
List<object> args = new List<object> { key };
306307

@@ -323,8 +324,8 @@ public bool[] MExists(RedisKey key, RedisValue[] items)
323324
/// <remarks><seealso href="https://redis.io/commands/bf.mexists"/></remarks>
324325
public async Task<bool[]> MExistsAsync(RedisKey key, RedisValue[] items)
325326
{
326-
if (items == null)
327-
throw new ArgumentNullException(nameof(items));
327+
if (items.Length < 1)
328+
throw new ArgumentOutOfRangeException(nameof(items));
328329

329330
List<object> args = new List<object> { key };
330331

@@ -348,7 +349,7 @@ public async Task<bool[]> MExistsAsync(RedisKey key, RedisValue[] items)
348349
/// created in size of the last sub-filter multiplied by expansion.</param>
349350
/// <param name="nonscaling">(Optional) <see langword="true"/> toprevent the filter
350351
/// from creating additional sub-filters if initial capacity is reached.</param>
351-
/// <returns><see langword="true"/> if executed correctly, <see langword="false"/> otherwise.</returns>
352+
/// <returns><see langword="true"/> if executed correctly, error otherwise/></returns>
352353
/// <remarks><seealso href="https://redis.io/commands/bf.reserve"/></remarks>
353354
public bool Reserve(RedisKey key, double errorRate, long capacity,
354355
int? expansion = null, bool nonscaling = false)
@@ -365,7 +366,7 @@ public bool Reserve(RedisKey key, double errorRate, long capacity,
365366
args.Add(BloomArgs.NONSCALING);
366367
}
367368

368-
return ResponseParser.ParseOKtoBoolean(_db.Execute(BF.RESERVE, args));
369+
return ResponseParser.OKtoBoolean(_db.Execute(BF.RESERVE, args));
369370
}
370371

371372
/// <summary>
@@ -378,7 +379,7 @@ public bool Reserve(RedisKey key, double errorRate, long capacity,
378379
/// created in size of the last sub-filter multiplied by expansion.</param>
379380
/// <param name="nonscaling">(Optional) <see langword="true"/> toprevent the filter
380381
/// from creating additional sub-filters if initial capacity is reached.</param>
381-
/// <returns><see langword="true"/> if executed correctly, <see langword="false"/> otherwise.</returns>
382+
/// <returns><see langword="true"/> if executed correctly, Error otherwise.</returns>
382383
/// <remarks><seealso href="https://redis.io/commands/bf.reserve"/></remarks>
383384
public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capacity,
384385
int? expansion = null, bool nonscaling = false)
@@ -396,7 +397,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
396397
}
397398

398399
var result = await _db.ExecuteAsync(BF.RESERVE, args);
399-
return ResponseParser.ParseOKtoBoolean(result);
400+
return ResponseParser.OKtoBoolean(result);
400401
}
401402

402403
/// <summary>
@@ -406,7 +407,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
406407
/// <param name="iterator">Iterator value; either 0 or the iterator from a previous invocation of this command.</param>
407408
/// <returns>Tuple of iterator and data.</returns>
408409
/// <remarks><seealso href="https://redis.io/commands/bf.scandump"/></remarks>
409-
public Tuple<long,Byte[]>? ScanDump(RedisKey key, long iterator)
410+
public Tuple<long,Byte[]> ScanDump(RedisKey key, long iterator)
410411
{
411412
return ResponseParser.ToScanDumpTuple(_db.Execute(BF.SCANDUMP, key, iterator));
412413
}
@@ -418,7 +419,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
418419
/// <param name="iterator">Iterator value; either 0 or the iterator from a previous invocation of this command.</param>
419420
/// <returns>Tuple of iterator and data.</returns>
420421
/// <remarks><seealso href="https://redis.io/commands/bf.scandump"/></remarks>
421-
public async Task<Tuple<long,Byte[]>?> ScanDumpAsync(RedisKey key, long iterator)
422+
public async Task<Tuple<long,Byte[]>> ScanDumpAsync(RedisKey key, long iterator)
422423
{
423424
var result = await _db.ExecuteAsync(BF.SCANDUMP, key, iterator);
424425
return ResponseParser.ToScanDumpTuple(result);

src/NRedisStack.Core/CountMinSketch/CmsCommands.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
4747
/// and the Amount by which the item counter is to be increased.</param>
4848
/// <returns>Count of each item after increment.</returns>
4949
/// <remarks><seealso href="https://redis.io/commands/cms.incrby"/></remarks>
50-
public long[]? IncrBy(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
50+
public long[] IncrBy(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
5151
{
5252
if (itemIncrements.Length < 1)
5353
throw new ArgumentException(nameof(itemIncrements));
@@ -69,7 +69,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
6969
/// and the Amount by which the item counter is to be increased.</param>
7070
/// <returns>Count of each item after increment.</returns>
7171
/// <remarks><seealso href="https://redis.io/commands/cms.incrby"/></remarks>
72-
public async Task<long[]?> IncrByAsync(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
72+
public async Task<long[]> IncrByAsync(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
7373
{
7474
if (itemIncrements.Length < 1)
7575
throw new ArgumentException(nameof(itemIncrements));
@@ -91,7 +91,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
9191
/// <param name="key">Name of the key to return information about.</param>
9292
/// <returns>Information of the sketch.</returns>
9393
/// <remarks><seealso href="https://redis.io/commands/cms.info"/></remarks>
94-
public CmsInformation? Info(RedisKey key)
94+
public CmsInformation Info(RedisKey key)
9595
{
9696
var info = _db.Execute(CMS.INFO, key);
9797
return ResponseParser.ToCmsInfo(info);
@@ -103,13 +103,12 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
103103
/// <param name="key">Name of the key to return information about.</param>
104104
/// <returns>Information of the sketch.</returns>
105105
/// <remarks><seealso href="https://redis.io/commands/cms.info"/></remarks>
106-
public async Task<CmsInformation?> InfoAsync(RedisKey key)
106+
public async Task<CmsInformation> InfoAsync(RedisKey key)
107107
{
108108
var info = await _db.ExecuteAsync(CMS.INFO, key);
109109
return ResponseParser.ToCmsInfo(info);
110110
}
111111

112-
//TODO: functions that returns OK cannot return false, they return OK or ERROR. fix this (the Redis functions that can return also false - will return 1 for true ans 0 for false)
113112
/// <summary>
114113
/// Initializes a Count-Min Sketch to dimensions specified by user.
115114
/// </summary>
@@ -121,7 +120,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
121120
/// <remarks><seealso href="https://redis.io/commands/cms.initbydim"/></remarks>
122121
public bool InitByDim(RedisKey key, long width, long depth)
123122
{
124-
return ResponseParser.ParseOKtoBoolean(_db.Execute(CMS.INITBYDIM, key, width, depth));
123+
return ResponseParser.OKtoBoolean(_db.Execute(CMS.INITBYDIM, key, width, depth));
125124
}
126125

127126
/// <summary>
@@ -136,7 +135,7 @@ public bool InitByDim(RedisKey key, long width, long depth)
136135
public async Task<bool> InitByDimAsync(RedisKey key, long width, long depth)
137136
{
138137
var result = await _db.ExecuteAsync(CMS.INITBYDIM, key, width, depth);
139-
return ResponseParser.ParseOKtoBoolean(result);
138+
return ResponseParser.OKtoBoolean(result);
140139
}
141140

142141
/// <summary>
@@ -149,7 +148,7 @@ public async Task<bool> InitByDimAsync(RedisKey key, long width, long depth)
149148
/// <remarks><seealso href="https://redis.io/commands/cms.initbyprob"/></remarks>
150149
public bool InitByProb(RedisKey key, double error, double probability)
151150
{
152-
return ResponseParser.ParseOKtoBoolean(_db.Execute(CMS.INITBYPROB, key, error, probability));
151+
return ResponseParser.OKtoBoolean(_db.Execute(CMS.INITBYPROB, key, error, probability));
153152
}
154153

155154
/// <summary>
@@ -163,7 +162,7 @@ public bool InitByProb(RedisKey key, double error, double probability)
163162
public async Task<bool> InitByProbAsync(RedisKey key, double error, double probability)
164163
{
165164
var result = await _db.ExecuteAsync(CMS.INITBYPROB, key, error, probability);
166-
return ResponseParser.ParseOKtoBoolean(result);
165+
return ResponseParser.OKtoBoolean(result);
167166
}
168167

169168
/// <summary>
@@ -178,7 +177,7 @@ public async Task<bool> InitByProbAsync(RedisKey key, double error, double proba
178177
public bool Merge(RedisValue destination, long numKeys, RedisValue[] source, long[]? weight = null)
179178
{
180179
if (source.Length < 1)
181-
throw new ArgumentNullException(nameof(source));
180+
throw new ArgumentOutOfRangeException(nameof(source));
182181

183182
List<object> args = new List<object> { destination, numKeys };
184183

@@ -190,7 +189,7 @@ public bool Merge(RedisValue destination, long numKeys, RedisValue[] source, lon
190189
foreach (var w in weight) args.Add(w);
191190
}
192191

193-
return ResponseParser.ParseOKtoBoolean(_db.Execute(CMS.MERGE, args));
192+
return ResponseParser.OKtoBoolean(_db.Execute(CMS.MERGE, args));
194193
}
195194

196195
/// <summary>
@@ -205,7 +204,7 @@ public bool Merge(RedisValue destination, long numKeys, RedisValue[] source, lon
205204
public async Task<bool> MergeAsync(RedisValue destination, long numKeys, RedisValue[] source, long[]? weight = null)
206205
{
207206
if (source.Length < 1)
208-
throw new ArgumentNullException(nameof(source));
207+
throw new ArgumentOutOfRangeException(nameof(source));
209208

210209
List<object> args = new List<object> { destination, numKeys };
211210

@@ -218,7 +217,7 @@ public async Task<bool> MergeAsync(RedisValue destination, long numKeys, RedisVa
218217
}
219218

220219
var result = await _db.ExecuteAsync(CMS.MERGE, args);
221-
return ResponseParser.ParseOKtoBoolean(result);
220+
return ResponseParser.OKtoBoolean(result);
222221
}
223222

224223
/// <summary>
@@ -228,10 +227,10 @@ public async Task<bool> MergeAsync(RedisValue destination, long numKeys, RedisVa
228227
/// <param name="items">One or more items for which to return the count.</param>
229228
/// <returns>Array with a min-count of each of the items in the sketch</returns>
230229
/// <remarks><seealso href="https://redis.io/commands/cms.query"/></remarks>
231-
public long[]? Query(RedisKey key, RedisValue[] items) //TODO: Create second version of this function using params for items input
230+
public long[] Query(RedisKey key, params RedisValue[] items)
232231
{
233232
if (items.Length < 1)
234-
throw new ArgumentNullException(nameof(items));
233+
throw new ArgumentOutOfRangeException(nameof(items));
235234

236235
List<object> args = new List<object> { key };
237236
foreach (var item in items) args.Add(item);
@@ -247,10 +246,10 @@ public async Task<bool> MergeAsync(RedisValue destination, long numKeys, RedisVa
247246
/// <param name="items">One or more items for which to return the count.</param>
248247
/// <returns>Array with a min-count of each of the items in the sketch</returns>
249248
/// <remarks><seealso href="https://redis.io/commands/cms.query"/></remarks>
250-
public async Task<long[]?> QueryAsync(RedisKey key, RedisValue[] items) //TODO: Create second version of this function using params for items input
249+
public async Task<long[]> QueryAsync(RedisKey key, params RedisValue[] items)
251250
{
252251
if (items.Length < 1)
253-
throw new ArgumentNullException(nameof(items));
252+
throw new ArgumentOutOfRangeException(nameof(items));
254253

255254
List<object> args = new List<object> { key };
256255
foreach (var item in items) args.Add(item);

0 commit comments

Comments
 (0)