Skip to content

Commit

Permalink
Make RespCommandsInfo optional for custom commands, remove json (#397)
Browse files Browse the repository at this point in the history
* Make RespCommandsInfo optional for custom commands, remove json

* update version

* Add custom commands json to test

* fix warning

* update trigger for auto-release when version is changed.
  • Loading branch information
badrishc authored May 17, 2024
1 parent c0ae5a9 commit ab9db61
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
10 changes: 8 additions & 2 deletions .azure/pipelines/azure-pipelines-external-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
# 1) update the name: string below (line 6) -- this is the version for the nuget package (e.g. 1.0.0)
# 2) update \libs\host\GarnetServer.cs readonly string version (~line 45) -- NOTE - these two values need to be the same
######################################
name: 1.0.9
trigger: none
name: 1.0.10
trigger:
branches:
include:
- main
paths:
include:
- .azure/pipelines/azure-pipelines-external-release.yml
resources:
repositories:
- repository: self
Expand Down
2 changes: 1 addition & 1 deletion libs/host/GarnetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GarnetServer : IDisposable
protected StoreWrapper storeWrapper;

// IMPORTANT: Keep the version in sync with .azure\pipelines\azure-pipelines-external-release.yml line ~6.
readonly string version = "1.0.9";
readonly string version = "1.0.10";

/// <summary>
/// Resp protocol version
Expand Down
6 changes: 3 additions & 3 deletions libs/server/Custom/CustomCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal int Register(string name, int numParams, CommandType type, CustomRawStr
throw new Exception("Out of registration space");

commandMap[id] = new CustomCommand(name, (byte)id, 1, numParams, type, customFunctions, expirationTicks);
customCommandsInfo.Add(name, commandInfo);
if (commandInfo != null) customCommandsInfo.Add(name, commandInfo);
return id;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ internal int Register(string name, int numParams, CommandType commandType, int o
throw new Exception("Out of registration space");

wrapper.commandMap[subCommand] = new CustomObjectCommand(name, (byte)objectTypeId, (byte)subCommand, 1, numParams, commandType, wrapper.factory);
customCommandsInfo.Add(name, commandInfo);
if (commandInfo != null) customCommandsInfo.Add(name, commandInfo);

return subCommand;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ internal int Register(string name, int numParams, CommandType commandType, int o
throw new Exception("Out of registration space");
wrapper.commandMap[subCommand] = new CustomObjectCommand(name, (byte)objectTypeId, (byte)subCommand, 1, numParams, commandType, wrapper.factory);

customCommandsInfo.Add(name, commandInfo);
if (commandInfo != null) customCommandsInfo.Add(name, commandInfo);

return (objectTypeId, subCommand);
}
Expand Down
6 changes: 3 additions & 3 deletions libs/server/Servers/RegisterApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RegisterApi(GarnetProvider provider)
/// >0 => set expiration to given value.
/// </param>
/// <returns>ID of the registered command</returns>
public int NewCommand(string name, int numParams, CommandType type, CustomRawStringFunctions customFunctions, RespCommandsInfo commandInfo, long expirationTicks = 0)
public int NewCommand(string name, int numParams, CommandType type, CustomRawStringFunctions customFunctions, RespCommandsInfo commandInfo = null, long expirationTicks = 0)
=> provider.StoreWrapper.customCommandManager.Register(name, numParams, type, customFunctions, commandInfo, expirationTicks);

/// <summary>
Expand Down Expand Up @@ -82,7 +82,7 @@ public void NewType(int type, CustomObjectFactory factory)
/// <param name="type">Type ID for factory, registered using RegisterType</param>
/// <param name="commandInfo">RESP command info</param>
/// <returns>ID of the registered command</returns>
public int NewCommand(string name, int numParams, CommandType commandType, int type, RespCommandsInfo commandInfo)
public int NewCommand(string name, int numParams, CommandType commandType, int type, RespCommandsInfo commandInfo = null)
=> provider.StoreWrapper.customCommandManager.Register(name, numParams, commandType, type, commandInfo);

/// <summary>
Expand All @@ -94,7 +94,7 @@ public int NewCommand(string name, int numParams, CommandType commandType, int t
/// <param name="factory">Custom factory for object</param>
/// <param name="commandInfo">RESP command info</param>
/// <returns>ID of the registered command</returns>
public (int, int) NewCommand(string name, int numParams, CommandType commandType, CustomObjectFactory factory, RespCommandsInfo commandInfo)
public (int, int) NewCommand(string name, int numParams, CommandType commandType, CustomObjectFactory factory, RespCommandsInfo commandInfo = null)
=> provider.StoreWrapper.customCommandManager.Register(name, numParams, commandType, factory, commandInfo);

}
Expand Down
3 changes: 0 additions & 3 deletions main/GarnetServer/GarnetServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
</ItemGroup>

<ItemGroup>
<None Update="CustomRespCommandsInfo.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="garnet.conf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
19 changes: 5 additions & 14 deletions main/GarnetServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using Garnet.common;
using Garnet.server;
Expand All @@ -16,8 +14,6 @@ namespace Garnet
/// </summary>
class Program
{
private static readonly string CustomRespCommandInfoJsonFileName = "CustomRespCommandsInfo.json";

static void Main(string[] args)
{
try
Expand Down Expand Up @@ -49,24 +45,19 @@ static void Main(string[] args)
/// </summary>
static bool TryRegisterExtensions(GarnetServer server)
{
var binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

if (!TryGetRespCommandsInfo(Path.Combine(binPath!, CustomRespCommandInfoJsonFileName), out var customCommandsInfo))
return false;

// Register custom command on raw strings (SETIFPM = "set if prefix match")
server.Register.NewCommand("SETIFPM", 2, CommandType.ReadModifyWrite, new SetIfPMCustomCommand(), customCommandsInfo["SETIFPM"]);
server.Register.NewCommand("SETIFPM", 2, CommandType.ReadModifyWrite, new SetIfPMCustomCommand());

// Register custom command on raw strings (SETWPIFPGT = "set with prefix, if prefix greater than")
server.Register.NewCommand("SETWPIFPGT", 2, CommandType.ReadModifyWrite, new SetWPIFPGTCustomCommand(), customCommandsInfo["SETWPIFPGT"]);
server.Register.NewCommand("SETWPIFPGT", 2, CommandType.ReadModifyWrite, new SetWPIFPGTCustomCommand());

// Register custom command on raw strings (DELIFM = "delete if value matches")
server.Register.NewCommand("DELIFM", 1, CommandType.ReadModifyWrite, new DeleteIfMatchCustomCommand(), customCommandsInfo["DELIFM"]);
server.Register.NewCommand("DELIFM", 1, CommandType.ReadModifyWrite, new DeleteIfMatchCustomCommand());

// Register custom commands on objects
var factory = new MyDictFactory();
server.Register.NewCommand("MYDICTSET", 2, CommandType.ReadModifyWrite, factory, customCommandsInfo["MYDICTSET"]);
server.Register.NewCommand("MYDICTGET", 1, CommandType.Read, factory, customCommandsInfo["MYDICTGET"]);
server.Register.NewCommand("MYDICTSET", 2, CommandType.ReadModifyWrite, factory);
server.Register.NewCommand("MYDICTGET", 1, CommandType.Read, factory);

// Register stored procedure to run a transactional command
server.Register.NewTransactionProc("READWRITETX", 3, () => new ReadWriteTxn());
Expand Down
2 changes: 1 addition & 1 deletion test/Garnet.test/Garnet.test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\..\main\GarnetServer\CustomRespCommandsInfo.json" Link="CustomRespCommandsInfo.json">
<EmbeddedResource Include="CustomRespCommandsInfo.json" Link="CustomRespCommandsInfo.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
Expand Down

0 comments on commit ab9db61

Please sign in to comment.