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

Use generics for CustomProcedure #725

Merged
merged 1 commit into from
Oct 16, 2024
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
3 changes: 2 additions & 1 deletion libs/server/Custom/CustomProcedureWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public abstract class CustomProcedure : CustomFunctions
/// Custom command implementation
/// </summary>
/// <param name="garnetApi"></param>
public abstract bool Execute(IGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output);
public abstract bool Execute<TGarnetApi>(TGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
where TGarnetApi : IGarnetApi;
}

class CustomProcedureWrapper
Expand Down
2 changes: 1 addition & 1 deletion main/GarnetServer/Extensions/SetStringAndList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Garnet
{
class SetStringAndList : CustomProcedure
{
public override bool Execute(IGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
public override bool Execute<TGarnetApi>(TGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
{
var offset = 0;
var key = GetNextArg(input, ref offset);
Expand Down
2 changes: 1 addition & 1 deletion main/GarnetServer/Extensions/Sum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Garnet
{
class Sum : CustomProcedure
{
public override bool Execute(IGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
public override bool Execute<TGarnetApi>(TGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
{
var offset = 0;
var sum = 0;
Expand Down
6 changes: 3 additions & 3 deletions test/Garnet.test/RespCustomCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace Garnet.test
{
public class LargeGet : CustomProcedure
{
public override bool Execute(IGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
public override bool Execute<TGarnetApi>(TGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
{
static bool ResetBuffer(IGarnetApi garnetApi, ref MemoryResult<byte> output, int buffOffset)
static bool ResetBuffer(TGarnetApi garnetApi, ref MemoryResult<byte> output, int buffOffset)
{
bool status = garnetApi.ResetScratchBuffer(buffOffset);
if (!status)
Expand Down Expand Up @@ -92,7 +92,7 @@ public override void Main<TGarnetApi>(TGarnetApi garnetApi, ArgSlice input, ref

public class OutOfOrderFreeBuffer : CustomProcedure
{
public override bool Execute(IGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
public override bool Execute<TGarnetApi>(TGarnetApi garnetApi, ArgSlice input, ref MemoryResult<byte> output)
{
var offset = 0;
var key = GetNextArg(input, ref offset);
Expand Down