Skip to content
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

Split TFCALL to TFCALL and TFCALLASYNC #178

Merged
merged 2 commits into from
Sep 3, 2023
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
24 changes: 18 additions & 6 deletions src/NRedisStack/Gears/GearsCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,31 @@ public static Dictionary<string, RedisResult>[] TFunctionList(this IDatabase db,
}

/// <summary>
/// Trigger a sync or async (Coroutine) function.
/// Trigger a sync function.
/// </summary>
/// <param name="libraryName">The library name contains the function.</param>
/// <param name="functionName">The function name to run.</param>
/// <param name="keys">keys that will be touched by the function.</param>
/// <param name="args">Additional argument to pass to the function.</param>
/// <param name="async">If true, Invoke an async function (Coroutine).</param>
/// <returns>The return value from the sync & async function on error in case of failure.</returns>
/// <remarks><seealso href="https://redis.io/commands/tfcall"/></remarks> //TODO: check this link when it's available
/// <remarks><seealso href="https://redis.io/commands/tfcallasync"/></remarks> //TODO: check this link when it's available
public static RedisResult TFCall(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null, bool async = false)
/// <remarks><seealso href="https://redis.io/commands/tfcall"/></remarks>
public static RedisResult TFCall_(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null)
{
return db.Execute(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async));
return db.Execute(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async : false));
}

/// <summary>
/// Trigger a async (Coroutine) function.
/// </summary>
/// <param name="libraryName">The library name contains the function.</param>
/// <param name="functionName">The function name to run.</param>
/// <param name="keys">keys that will be touched by the function.</param>
/// <param name="args">Additional argument to pass to the function.</param>
/// <returns>The return value from the sync & async function on error in case of failure.</returns>
/// <remarks><seealso href="https://redis.io/commands/tfcallasync"/></remarks>
public static RedisResult TFCallAsync_(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null)
{
return db.Execute(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async : true));
}
}
}
23 changes: 18 additions & 5 deletions src/NRedisStack/Gears/GearsCommandsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,31 @@ public static async Task<Dictionary<string, RedisResult>[]> TFunctionListAsync(t
}

/// <summary>
/// Invoke a sync or async (Coroutine) function.
/// Trigger a sync function.
/// </summary>
/// <param name="libraryName">The library name contains the function.</param>
/// <param name="functionName">The function name to run.</param>
/// <param name="keys">keys that will be touched by the function.</param>
/// <param name="args">Additional argument to pass to the function.</param>
/// <param name="async">If true, Invoke an async function (Coroutine).</param>
/// <returns>The return value from the sync & async function on error in case of failure.</returns>
/// <remarks><seealso href="https://redis.io/commands/"/></remarks> //TODO: add link to the command when it's available
public static async Task<RedisResult> TFCallAsync(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null, bool async = false)
/// <remarks><seealso href="https://redis.io/commands/tfcall"/></remarks>
public async static Task<RedisResult> TFCall_Async(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null)
{
return await db.ExecuteAsync(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async : false));
}

/// <summary>
/// Trigger a async (Coroutine) function.
/// </summary>
/// <param name="libraryName">The library name contains the function.</param>
/// <param name="functionName">The function name to run.</param>
/// <param name="keys">keys that will be touched by the function.</param>
/// <param name="args">Additional argument to pass to the function.</param>
/// <returns>The return value from the sync & async function on error in case of failure.</returns>
/// <remarks><seealso href="https://redis.io/commands/tfcallasync"/></remarks>
public async static Task<RedisResult> TFCallAsync_Async(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null)
{
return await db.ExecuteAsync(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async));
return await db.ExecuteAsync(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async : true));
}
}
}
1 change: 1 addition & 0 deletions src/NRedisStack/Graph/IGraphCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace NRedisStack
{
[Obsolete("RedisGraph is not supported since Redis 7.2 (https://redis.com/blog/redisgraph-eol/)")]
public interface IGraphCommands
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/NRedisStack/Graph/IGraphCommandsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace NRedisStack
{
[Obsolete("RedisGraph is not supported since Redis 7.2 (https://redis.com/blog/redisgraph-eol/)")]
public interface IGraphCommandsAsync
{
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions tests/NRedisStack.Tests/Gears/GearsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void TestTFCall()
TryDeleteLib(db, "lib", "lib1", "lib2", "lib3");

Assert.True(db.TFunctionLoad(GenerateLibCode("lib")));
Assert.Equal("bar", db.TFCall("lib", "foo", async: false).ToString());
Assert.Equal("bar", db.TFCall("lib", "foo", async: true).ToString());
Assert.Equal("bar", db.TFCall_("lib", "foo").ToString());
Assert.Equal("bar", db.TFCallAsync_("lib", "foo").ToString());

Assert.True(db.TFunctionDelete("lib"));
}
Expand All @@ -117,8 +117,8 @@ public async Task TestTFCallAsync()
TryDeleteLib(db, "lib", "lib1", "lib2", "lib3");

Assert.True(await db.TFunctionLoadAsync(GenerateLibCode("lib")));
Assert.Equal("bar", (await db.TFCallAsync("lib", "foo", async: false)).ToString());
Assert.Equal("bar", (await db.TFCallAsync("lib", "foo", async: true)).ToString());
Assert.Equal("bar", (await db.TFCall_Async("lib", "foo")).ToString());
Assert.Equal("bar", (await db.TFCallAsync_Async("lib", "foo")).ToString());
Copy link
Contributor

Choose a reason for hiding this comment

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

And the tests :D


Assert.True(await db.TFunctionDeleteAsync("lib"));
}
Expand Down