Skip to content

Start addin Tdigest commands #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NRedisStack.Core/Auxiliary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace NRedisStack.Core
{
public static class Auxiliary
{
public static List<object> MergeArgs(RedisKey key, RedisValue[] items)
public static List<object> MergeArgs(RedisKey key, params RedisValue[] items)
{
var args = new List<object> { key };
foreach (var item in items) args.Add(item);
Expand Down
53 changes: 27 additions & 26 deletions src/NRedisStack.Core/Bloom/BloomCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
/// <param name="key">Name of the key to return information about.</param>
/// <returns>Information of the filter.</returns>
/// <remarks><seealso href="https://redis.io/commands/bf.info"/></remarks>
public BloomInformation? Info(RedisKey key)
public BloomInformation Info(RedisKey key)
{
var info = _db.Execute(BF.INFO, key);
return ResponseParser.ToBloomInfo(info);
Expand All @@ -82,7 +82,7 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
/// <param name="key">Name of the key to return information about.</param>
/// <returns>Information of the filter.</returns>
/// <remarks><seealso href="https://redis.io/commands/bf.info"/></remarks>
public async Task<BloomInformation?> InfoAsync(RedisKey key)
public async Task<BloomInformation> InfoAsync(RedisKey key)
{
var info = await _db.ExecuteAsync(BF.INFO, key);
return ResponseParser.ToBloomInfo(info);
Expand All @@ -108,8 +108,8 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
double? error = null, int? expansion = null,
bool nocreate = false, bool nonscaling = false)
{
if (items == null)
throw new ArgumentNullException(nameof(items));
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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


if (error != null)
{
args.Add(BloomArgs.ERROR);
Expand Down Expand Up @@ -171,8 +172,8 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
double? error = null, int? expansion = null,
bool nocreate = false, bool nonscaling = false)
{
if (items == null)
throw new ArgumentNullException(nameof(items));
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

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

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

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

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

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

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

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

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

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

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

return ResponseParser.ParseOKtoBoolean(_db.Execute(BF.RESERVE, args));
return ResponseParser.OKtoBoolean(_db.Execute(BF.RESERVE, args));
}

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

var result = await _db.ExecuteAsync(BF.RESERVE, args);
return ResponseParser.ParseOKtoBoolean(result);
return ResponseParser.OKtoBoolean(result);
}

/// <summary>
Expand All @@ -406,7 +407,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
/// <param name="iterator">Iterator value; either 0 or the iterator from a previous invocation of this command.</param>
/// <returns>Tuple of iterator and data.</returns>
/// <remarks><seealso href="https://redis.io/commands/bf.scandump"/></remarks>
public Tuple<long,Byte[]>? ScanDump(RedisKey key, long iterator)
public Tuple<long,Byte[]> ScanDump(RedisKey key, long iterator)
{
return ResponseParser.ToScanDumpTuple(_db.Execute(BF.SCANDUMP, key, iterator));
}
Expand All @@ -418,7 +419,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
/// <param name="iterator">Iterator value; either 0 or the iterator from a previous invocation of this command.</param>
/// <returns>Tuple of iterator and data.</returns>
/// <remarks><seealso href="https://redis.io/commands/bf.scandump"/></remarks>
public async Task<Tuple<long,Byte[]>?> ScanDumpAsync(RedisKey key, long iterator)
public async Task<Tuple<long,Byte[]>> ScanDumpAsync(RedisKey key, long iterator)
{
var result = await _db.ExecuteAsync(BF.SCANDUMP, key, iterator);
return ResponseParser.ToScanDumpTuple(result);
Expand Down
33 changes: 16 additions & 17 deletions src/NRedisStack.Core/CountMinSketch/CmsCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
/// and the Amount by which the item counter is to be increased.</param>
/// <returns>Count of each item after increment.</returns>
/// <remarks><seealso href="https://redis.io/commands/cms.incrby"/></remarks>
public long[]? IncrBy(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
public long[] IncrBy(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
{
if (itemIncrements.Length < 1)
throw new ArgumentException(nameof(itemIncrements));
Expand All @@ -69,7 +69,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
/// and the Amount by which the item counter is to be increased.</param>
/// <returns>Count of each item after increment.</returns>
/// <remarks><seealso href="https://redis.io/commands/cms.incrby"/></remarks>
public async Task<long[]?> IncrByAsync(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
public async Task<long[]> IncrByAsync(RedisKey key, Tuple<RedisValue, long>[] itemIncrements)
{
if (itemIncrements.Length < 1)
throw new ArgumentException(nameof(itemIncrements));
Expand All @@ -91,7 +91,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
/// <param name="key">Name of the key to return information about.</param>
/// <returns>Information of the sketch.</returns>
/// <remarks><seealso href="https://redis.io/commands/cms.info"/></remarks>
public CmsInformation? Info(RedisKey key)
public CmsInformation Info(RedisKey key)
{
var info = _db.Execute(CMS.INFO, key);
return ResponseParser.ToCmsInfo(info);
Expand All @@ -103,13 +103,12 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
/// <param name="key">Name of the key to return information about.</param>
/// <returns>Information of the sketch.</returns>
/// <remarks><seealso href="https://redis.io/commands/cms.info"/></remarks>
public async Task<CmsInformation?> InfoAsync(RedisKey key)
public async Task<CmsInformation> InfoAsync(RedisKey key)
{
var info = await _db.ExecuteAsync(CMS.INFO, key);
return ResponseParser.ToCmsInfo(info);
}

//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)
/// <summary>
/// Initializes a Count-Min Sketch to dimensions specified by user.
/// </summary>
Expand All @@ -121,7 +120,7 @@ public async Task<long> IncrByAsync(RedisKey key, RedisValue item, long incremen
/// <remarks><seealso href="https://redis.io/commands/cms.initbydim"/></remarks>
public bool InitByDim(RedisKey key, long width, long depth)
{
return ResponseParser.ParseOKtoBoolean(_db.Execute(CMS.INITBYDIM, key, width, depth));
return ResponseParser.OKtoBoolean(_db.Execute(CMS.INITBYDIM, key, width, depth));
}

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

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

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

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

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

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

return ResponseParser.ParseOKtoBoolean(_db.Execute(CMS.MERGE, args));
return ResponseParser.OKtoBoolean(_db.Execute(CMS.MERGE, args));
}

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

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

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

var result = await _db.ExecuteAsync(CMS.MERGE, args);
return ResponseParser.ParseOKtoBoolean(result);
return ResponseParser.OKtoBoolean(result);
}

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

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

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