Skip to content

Review #28

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 7 commits into from
Aug 31, 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/Auxiliary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class Auxiliary
{
public static List<object> MergeArgs(RedisKey key, params RedisValue[] items)
{
var args = new List<object> { key };
var args = new List<object>(items.Length + 1) { key };
foreach (var item in items) args.Add(item);
return args;
}
Expand Down
79 changes: 79 additions & 0 deletions src/NRedisStack/Bloom/BloomAux.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using NRedisStack.Literals;
using NRedisStack.Literals.Enums;
using NRedisStack.DataTypes;
using NRedisStack.Extensions;
using StackExchange.Redis;

namespace NRedisStack
{
public static class BloomAux
{
public static List<object> BuildInsertArgs(RedisKey key, RedisValue[] items, int? capacity,
double? error, int? expansion, bool nocreate, bool nonscaling)
{
var args = new List<object> { key };
args.AddCapacity(capacity);
args.AddError(error);
args.AddExpansion(expansion);
args.AddNoCreate(nocreate);
args.AddNoScaling(nonscaling);
args.AddItems(items);

return args;
}

private static void AddItems(this List<object> args, RedisValue[] items)
{
args.Add(BloomArgs.ITEMS);
foreach (var item in items)
{
args.Add(item);
}
}

private static void AddNoScaling(this List<object> args, bool nonscaling)
{
if (nonscaling)
{
args.Add(BloomArgs.NONSCALING);
}
}

private static void AddNoCreate(this List<object> args, bool nocreate)
{
if (nocreate)
{
args.Add(BloomArgs.NOCREATE);
}
}

private static void AddExpansion(this List<object> args, int? expansion)
{
if (expansion != null)
{
args.Add(BloomArgs.EXPANSION);
args.Add(expansion);
}
}

private static void AddError(this List<object> args, double? error)
{
if (error != null)
{
args.Add(BloomArgs.ERROR);
args.Add(error);
}
}

private static void AddCapacity(this List<object> args, int? capacity)
{
if (capacity != null)
{
args.Add(BloomArgs.CAPACITY);
args.Add(capacity);
}
}
}
}
106 changes: 17 additions & 89 deletions src/NRedisStack/Bloom/BloomCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
/// <remarks><seealso href="https://redis.io/commands/bf.info"/></remarks>
public BloomInformation Info(RedisKey key)
{
var info = _db.Execute(BF.INFO, key);
return ResponseParser.ToBloomInfo(info);
return _db.Execute(BF.INFO, key).ToBloomInfo();
}

/// <summary>
Expand All @@ -85,7 +84,7 @@ public BloomInformation Info(RedisKey key)
public async Task<BloomInformation> InfoAsync(RedisKey key)
{
var info = await _db.ExecuteAsync(BF.INFO, key);
return ResponseParser.ToBloomInfo(info);
return info.ToBloomInfo();
}

/// <summary>
Expand All @@ -111,45 +110,9 @@ public bool[] Insert(RedisKey key, RedisValue[] items, int? capacity = null,
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

if (capacity != null)
{
args.Add(BloomArgs.CAPACITY);
args.Add(capacity);
}


if (error != null)
{
args.Add(BloomArgs.ERROR);
args.Add(error);
}

if (expansion != null)
{
args.Add(BloomArgs.EXPANSION);
args.Add(expansion);
}

if (nocreate)
{
args.Add(BloomArgs.NOCREATE);

}

if (nonscaling)
{
args.Add(BloomArgs.NONSCALING);
}

args.Add(BloomArgs.ITEMS);
foreach (var item in items)
{
args.Add(item);
}

return ResponseParser.ToBooleanArray(_db.Execute(BF.INSERT, args));
var args = BloomAux.BuildInsertArgs(key, items, capacity, error, expansion, nocreate, nonscaling);

return _db.Execute(BF.INSERT, args).ToBooleanArray();
}

/// <summary>
Expand All @@ -175,45 +138,10 @@ public async Task<bool[]> InsertAsync(RedisKey key, RedisValue[] items, int? cap
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

if (capacity != null)
{
args.Add(BloomArgs.CAPACITY);
args.Add(capacity);
}

if (error != null)
{
args.Add(BloomArgs.ERROR);
args.Add(error);
}

if (expansion != null)
{
args.Add(BloomArgs.EXPANSION);
args.Add(expansion);
}

if (nocreate)
{
args.Add(BloomArgs.NOCREATE);

}

if (nonscaling)
{
args.Add(BloomArgs.NONSCALING);
}

args.Add(BloomArgs.ITEMS);
foreach (var item in items)
{
args.Add(item);
}
var args = BloomAux.BuildInsertArgs(key, items, capacity, error, expansion, nocreate, nonscaling);

var result = await _db.ExecuteAsync(BF.INSERT, args);
return ResponseParser.ToBooleanArray(result);
return result.ToBooleanArray();
}

/// <summary>
Expand All @@ -226,7 +154,7 @@ public async Task<bool[]> InsertAsync(RedisKey key, RedisValue[] items, int? cap
/// <remarks><seealso href="https://redis.io/commands/bf.loadchunk"/></remarks>
public bool LoadChunk(RedisKey key, long iterator, Byte[] data)
{
return ResponseParser.OKtoBoolean(_db.Execute(BF.LOADCHUNK, key, iterator, data));
return _db.Execute(BF.LOADCHUNK, key, iterator, data).OKtoBoolean();
}

/// <summary>
Expand All @@ -240,7 +168,7 @@ public bool LoadChunk(RedisKey key, long iterator, Byte[] data)
public async Task<bool> LoadChunkAsync(RedisKey key, long iterator, Byte[] data)
{
var result = await _db.ExecuteAsync(BF.LOADCHUNK, key, iterator, data);
return ResponseParser.OKtoBoolean(result);
return result.OKtoBoolean();
}

/// <summary>
Expand All @@ -263,7 +191,7 @@ public bool[] MAdd(RedisKey key, params RedisValue[] items)
args.Add(item);
}

return ResponseParser.ToBooleanArray(_db.Execute(BF.MADD, args));
return _db.Execute(BF.MADD, args).ToBooleanArray();
}

/// <summary>
Expand All @@ -287,7 +215,7 @@ public async Task<bool[]> MAddAsync(RedisKey key, params RedisValue[] items)
}

var result = await _db.ExecuteAsync(BF.MADD, args);
return ResponseParser.ToBooleanArray(result);
return result.ToBooleanArray();
}

/// <summary>
Expand All @@ -310,7 +238,7 @@ public bool[] MExists(RedisKey key, RedisValue[] items)
args.Add(item);
}

return ResponseParser.ToBooleanArray(_db.Execute(BF.MEXISTS, args));
return _db.Execute(BF.MEXISTS, args).ToBooleanArray();

}

Expand All @@ -335,7 +263,7 @@ public async Task<bool[]> MExistsAsync(RedisKey key, RedisValue[] items)
}

var result = await _db.ExecuteAsync(BF.MEXISTS, args);
return ResponseParser.ToBooleanArray(result);
return result.ToBooleanArray();

}

Expand Down Expand Up @@ -366,7 +294,7 @@ public bool Reserve(RedisKey key, double errorRate, long capacity,
args.Add(BloomArgs.NONSCALING);
}

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

/// <summary>
Expand Down Expand Up @@ -397,7 +325,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
}

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

/// <summary>
Expand All @@ -409,7 +337,7 @@ public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capaci
/// <remarks><seealso href="https://redis.io/commands/bf.scandump"/></remarks>
public Tuple<long,Byte[]> ScanDump(RedisKey key, long iterator)
{
return ResponseParser.ToScanDumpTuple(_db.Execute(BF.SCANDUMP, key, iterator));
return _db.Execute(BF.SCANDUMP, key, iterator).ToScanDumpTuple();
}

/// <summary>
Expand All @@ -422,7 +350,7 @@ public Tuple<long,Byte[]> ScanDump(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);
return result.ToScanDumpTuple();
}
}
}
12 changes: 6 additions & 6 deletions src/NRedisStack/Bloom/Literals/CommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace NRedisStack.Literals
{
internal class BloomArgs
{
public static string CAPACITY => "CAPACITY";
public static string ERROR => "ERROR";
public static string EXPANSION => "EXPANSION";
public static string NOCREATE => "NOCREATE";
public static string NONSCALING => "NONSCALING";
public static string ITEMS => "ITEMS";
public const string CAPACITY = "CAPACITY";
public const string ERROR = "ERROR";
public const string EXPANSION = "EXPANSION";
public const string NOCREATE = "NOCREATE";
public const string NONSCALING = "NONSCALING";
public const string ITEMS = "ITEMS";
}
}
18 changes: 9 additions & 9 deletions src/NRedisStack/Bloom/Literals/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
{
internal class BF
{
public static string ADD => "BF.ADD";
public static string EXISTS => "BF.EXISTS";
public static string INFO => "BF.INFO";
public static string INSERT => "BF.INSERT";
public static string LOADCHUNK => "BF.LOADCHUNK";
public static string MADD => "BF.MADD";
public static string MEXISTS => "BF.MEXISTS";
public static string RESERVE => "BF.RESERVE";
public static string SCANDUMP => "BF.SCANDUMP";
public const string ADD = "BF.ADD";
public const string EXISTS = "BF.EXISTS";
public const string INFO = "BF.INFO";
public const string INSERT = "BF.INSERT";
public const string LOADCHUNK = "BF.LOADCHUNK";
public const string MADD = "BF.MADD";
public const string MEXISTS = "BF.MEXISTS";
public const string RESERVE = "BF.RESERVE";
public const string SCANDUMP = "BF.SCANDUMP";
}
}
Loading