website/docs/dev/garnet-api.md
The IGarnetApi interface contains the operators exposed to the public API, which ultimately perform operations over the keys stored in Garnet. It inherits from IGarnetReadApi (read-only commands interface) and IGarnetAdvancedApi (advanced API calls).
For adding a new operator or command to the API, add a new method signature to the IGarnetReadApi interface in case the command performs read-only operations, or IGarnetApi otherwise.
If you are trying to add a command for your specific Garnet server instance, see Custom Commands
To add a new command to Garnet, follow these steps:
[ObjectName]Operation enum in Garnet.server/Objects/[ObjectName]/[ObjectName]Object.csRespCommand enum in Garnet.server/Resp/RespCommand.cs.Garnet.server/Resp/RespCommand.cs. If the command has a fixed number of arguments, add parsing logic to the FastParseCommand method. Otherwise, add parsing logic to the FastParseArrayCommand method.Garnet.server/API/IGarnetAPI.cs).Garnet.server/Resp/Objects/[ObjectName]Commands.cs, while others will reside under Garnet.server/Resp/[Admin|Array|Basic|etc...]Commands.cs, depending on the command type).Garnet.server/Resp/RespCommand.cs, add the new command case to the ProcessBasicCommands or ProcessArrayCommands method respectively, calling the method that was added in step #4.Garnet.server/Storage/Session/ObjectStore/[ObjectName]Ops.cs, while main store operations will mainly reside under Garnet.server/Storage/Session/MainStore/MainStoreOps.cs, with some exceptions).[Read|RMW]ObjectStoreOperation[WithOutput], which in turn will call the Operate method in Garnet.server/Objects/[ObjectName]/[ObjectName]Object.cs, where you will have to add a new case for the command and and the object-specific command implementation in Garnet.server/Objects/[ObjectName]/[ObjectName]ObjectImpl.csTransactionManager instance). You can then operate on multiple objects (for instance using the GET & SET operations).Read or RMW methods. If you are calling RMW, you will need to implement the initialization and in-place / copy update functionality of the new command in Garnet.server/Storage/Functions/MainStore/RMWMethods.cs.TransactionManager.GetKeys method and return the appropriate key locks required by the command (Garnet.server/Transaction/TxnKeyManager.cs).SE.Redis and LightClient, if applicable. For object commands, add tests to Garnet.test/Resp[ObjectName]Tests.cs. For other commands, add to Garnet.test/RespTests.cs or Garnet.test/Resp[AdminCommands|etc...]Tests.cs, depending on the command type.website/docs/commands/, and specify the command as supported in website/docs/commands/api-compatibility.md.:::tip Before you start implementing your command logic, add a basic test that calls the new command, it will be easier to debug and implement missing logic as you go along. :::
Each supported RESP command in Garnet should have an entry in Garnet.server/Resp/RespCommandsInfo.json, specifying the command's info.
A command's info can be added manually, but we recommend using the CommandInfoUpdater tool to update the JSON file (can be found under playground/).
The CommandInfoUpdater tool calculates the difference between existing commands in Garnet.server/Resp/RespCommandsInfo.json and commands specified in CommandInfoUpdater/SupportedCommands.cs. It then attempts to add/remove commands' info as necessary.
Info for Garnet-only commands is retrieved from CommandInfoUpdater/GarnetCommandsInfo.json, and info for other RESP commands is retrieved from an external RESP server (which you will need to run locally or have access to in order to run this tool).
To add command info to Garnet, follow these steps:
CommandInfoUpdater/SupportedCommands.cs.CommandInfoUpdater/GarnetCommandsInfo.json.-h or --help).cd playground/CommandInfoUpdater
dotnet run -- --output ../../libs/resources