Skip to content

Creating CommandBuilders #42

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 26 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
56ef34a
Creating ExecuteInTransaction function
shacharPash Nov 16, 2022
f1ebf4e
test cpmmit
shacharPash Nov 17, 2022
d6060d7
Add SerializedCommands & BloomSerializer
shacharPash Nov 17, 2022
92439ee
Creating ExecuteInTransaction function
shacharPash Nov 16, 2022
a93c134
test cpmmit
shacharPash Nov 17, 2022
1c6d286
Add SerializedCommands & BloomSerializer
shacharPash Nov 17, 2022
dedd93f
Fix SerializedCommand
shacharPash Nov 21, 2022
55bc897
Merge branch 'SupportTransactions' of github.com:redis/NRedisStack in…
shacharPash Nov 21, 2022
a6d2ec4
Add CmsCommandBuilder
shacharPash Nov 21, 2022
b524ada
Naming
shacharPash Nov 21, 2022
6929c05
Add CuckooCommndBuilder
shacharPash Nov 21, 2022
fdf6a89
Add TdigestCommndBuilder
shacharPash Nov 21, 2022
ca97a3f
Add TopKCommandBuilder
shacharPash Nov 22, 2022
c55a528
Add JsonCommandBuilder
shacharPash Nov 22, 2022
f2cc6a3
Add SearchCommandBuilder
shacharPash Nov 22, 2022
ba2d420
Fix Tests
shacharPash Nov 22, 2022
2855bcc
Add TimeSeriesCommandBuilder
shacharPash Nov 22, 2022
38c8bc8
Remove Unessesary using
shacharPash Nov 22, 2022
bac799c
Update Branch
shacharPash Nov 22, 2022
6b4100e
Connecting GraphCommands to the documentation of the interface
shacharPash Nov 22, 2022
9cc41d2
Add GraphCommandBuilder
shacharPash Nov 23, 2022
8899813
Update Version to 0.4.0
shacharPash Nov 29, 2022
ed7c24c
Writing README
shacharPash Nov 29, 2022
d5a9dec
update words to ignor
shacharPash Nov 29, 2022
52205e5
update words to ignore
shacharPash Nov 29, 2022
dfa282d
update words to ignore2
shacharPash Nov 29, 2022
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
11 changes: 11 additions & 0 deletions src/NRedisStack/Auxiliary.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;

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

return args.ToArray();
}

public static RedisResult Execute(this IDatabase db, SerializedCommand command)
{
return db.Execute(command.Command, command.Args);
}

public async static Task<RedisResult> ExecuteAsync(this IDatabase db, SerializedCommand command)
{
return await db.ExecuteAsync(command.Command, command.Args);
}
}
}
95 changes: 95 additions & 0 deletions src/NRedisStack/Bloom/BloomCommandBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using NRedisStack.Literals;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
namespace NRedisStack
{

public static class BloomCommandBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO comment the class too. Let's explain to users why this exists, why it's an issue.

{
public static SerializedCommand Add(RedisKey key, RedisValue item)
{
return new SerializedCommand(BF.ADD, key, item);
}

public static SerializedCommand Exists(RedisKey key, RedisValue item)
{
return new SerializedCommand(BF.EXISTS, key, item);
}

public static SerializedCommand Info(RedisKey key)
{
return new SerializedCommand(BF.INFO, key);
}

public static SerializedCommand Insert(RedisKey key, RedisValue[] items, int? capacity = null,
double? error = null, int? expansion = null,
bool nocreate = false, bool nonscaling = false)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

var args = BloomAux.BuildInsertArgs(key, items, capacity, error, expansion, nocreate, nonscaling);

return new SerializedCommand(BF.INSERT, args);
}

public static SerializedCommand LoadChunk(RedisKey key, long iterator, Byte[] data)
{
return new SerializedCommand(BF.LOADCHUNK, key, iterator, data);
}

public static SerializedCommand MAdd(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

return new SerializedCommand(BF.MADD, args);
}

public static SerializedCommand MExists(RedisKey key, RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

return new SerializedCommand(BF.MEXISTS, args);

}

public static SerializedCommand Reserve(RedisKey key, double errorRate, long capacity,
int? expansion = null, bool nonscaling = false)
{
List<object> args = new List<object> { key, errorRate, capacity };

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

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

return new SerializedCommand(BF.RESERVE, args);
}

public static SerializedCommand ScanDump(RedisKey key, long iterator)
{
return new SerializedCommand(BF.SCANDUMP, key, iterator);
}
}
}
121 changes: 18 additions & 103 deletions src/NRedisStack/Bloom/BloomCommands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NRedisStack.Bloom.DataTypes;
using NRedisStack.Literals;
using StackExchange.Redis;
namespace NRedisStack
{
Expand All @@ -15,39 +14,37 @@ public BloomCommands(IDatabase db)
/// <inheritdoc/>
public bool Add(RedisKey key, RedisValue item)
{
return _db.Execute(BF.ADD, key, item).ToString() == "1";
return _db.Execute(BloomCommandBuilder.Add(key, item)).ToString() == "1";
}

/// <inheritdoc/>
public async Task<bool> AddAsync(RedisKey key, RedisValue item)
{
var result = await _db.ExecuteAsync(BF.ADD, key, item);
return result.ToString() == "1";
return (await _db.ExecuteAsync(BloomCommandBuilder.Add(key, item))).ToString() == "1";
}

/// <inheritdoc/>
public bool Exists(RedisKey key, RedisValue item)
{
return _db.Execute(BF.EXISTS, key, item).ToString() == "1";
return _db.Execute(BloomCommandBuilder.Exists(key, item)).ToString() == "1";
}

/// <inheritdoc/>
public async Task<bool> ExistsAsync(RedisKey key, RedisValue item)
{
var result = await _db.ExecuteAsync(BF.EXISTS, key, item);
return result.ToString() == "1";
return (await _db.ExecuteAsync(BloomCommandBuilder.Exists(key, item))).ToString() == "1";
}

/// <inheritdoc/>
public BloomInformation Info(RedisKey key)
{
return _db.Execute(BF.INFO, key).ToBloomInfo();
return _db.Execute(BloomCommandBuilder.Info(key)).ToBloomInfo();
}

/// <inheritdoc/>
public async Task<BloomInformation> InfoAsync(RedisKey key)
{
var info = await _db.ExecuteAsync(BF.INFO, key);
var info = (await _db.ExecuteAsync(BloomCommandBuilder.Info(key)));
return info.ToBloomInfo();
}

Expand All @@ -56,159 +53,77 @@ public bool[] Insert(RedisKey key, RedisValue[] items, int? capacity = null,
double? error = null, int? expansion = null,
bool nocreate = false, bool nonscaling = false)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

var args = BloomAux.BuildInsertArgs(key, items, capacity, error, expansion, nocreate, nonscaling);

return _db.Execute(BF.INSERT, args).ToBooleanArray();
return _db.Execute(BloomCommandBuilder.Insert(key, items, capacity, error, expansion, nocreate, nonscaling)).ToBooleanArray();
}

/// <inheritdoc/>
public async Task<bool[]> InsertAsync(RedisKey key, RedisValue[] items, int? capacity = null,
double? error = null, int? expansion = null,
bool nocreate = false, bool nonscaling = false)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

var args = BloomAux.BuildInsertArgs(key, items, capacity, error, expansion, nocreate, nonscaling);

var result = await _db.ExecuteAsync(BF.INSERT, args);
return result.ToBooleanArray();
return (await _db.ExecuteAsync(BloomCommandBuilder.Insert(key, items, capacity, error, expansion, nocreate, nonscaling))).ToBooleanArray();
}

/// <inheritdoc/>
public bool LoadChunk(RedisKey key, long iterator, Byte[] data)
{
return _db.Execute(BF.LOADCHUNK, key, iterator, data).OKtoBoolean();
return _db.Execute(BloomCommandBuilder.LoadChunk(key, iterator, data)).OKtoBoolean();
}

/// <inheritdoc/>
public async Task<bool> LoadChunkAsync(RedisKey key, long iterator, Byte[] data)
{
var result = await _db.ExecuteAsync(BF.LOADCHUNK, key, iterator, data);
return result.OKtoBoolean();
return (await _db.ExecuteAsync(BloomCommandBuilder.LoadChunk(key, iterator, data))).OKtoBoolean();
}

/// <inheritdoc/>
public bool[] MAdd(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

return _db.Execute(BF.MADD, args).ToBooleanArray();
return _db.Execute(BloomCommandBuilder.MAdd(key, items)).ToBooleanArray();
}

/// <inheritdoc/>
public async Task<bool[]> MAddAsync(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

var result = await _db.ExecuteAsync(BF.MADD, args);
return result.ToBooleanArray();
return (await _db.ExecuteAsync(BloomCommandBuilder.MAdd(key, items))).ToBooleanArray();
}

/// <inheritdoc/>
public bool[] MExists(RedisKey key, RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

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

return _db.Execute(BloomCommandBuilder.MExists(key, items)).ToBooleanArray();
}

/// <inheritdoc/>
public async Task<bool[]> MExistsAsync(RedisKey key, RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));

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

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

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

return (await _db.ExecuteAsync(BloomCommandBuilder.MExists(key, items))).ToBooleanArray();
}

/// <inheritdoc/>
public bool Reserve(RedisKey key, double errorRate, long capacity,
int? expansion = null, bool nonscaling = false)
{
List<object> args = new List<object> { key, errorRate, capacity };

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

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

return _db.Execute(BF.RESERVE, args).OKtoBoolean();
return _db.Execute(BloomCommandBuilder.Reserve(key, errorRate, capacity, expansion, nonscaling)).OKtoBoolean();
}

/// <inheritdoc/>
public async Task<bool> ReserveAsync(RedisKey key, double errorRate, long capacity,
int? expansion = null, bool nonscaling = false)
{
List<object> args = new List<object> { key, errorRate, capacity };

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

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

var result = await _db.ExecuteAsync(BF.RESERVE, args);
return result.OKtoBoolean();
return (await _db.ExecuteAsync(BloomCommandBuilder.Reserve(key, errorRate, capacity, expansion, nonscaling))).OKtoBoolean();
}

/// <inheritdoc/>
public Tuple<long, Byte[]> ScanDump(RedisKey key, long iterator)
{
return _db.Execute(BF.SCANDUMP, key, iterator).ToScanDumpTuple();
return _db.Execute(BloomCommandBuilder.ScanDump(key, iterator)).ToScanDumpTuple();
}

/// <inheritdoc/>
public async Task<Tuple<long, Byte[]>> ScanDumpAsync(RedisKey key, long iterator)
{
var result = await _db.ExecuteAsync(BF.SCANDUMP, key, iterator);
return result.ToScanDumpTuple();
return (await _db.ExecuteAsync(BloomCommandBuilder.ScanDump(key, iterator))).ToScanDumpTuple();
}
}
}
Loading