Modules
Modules help bundle related custom commands, procedures and transactions into a single binary. Once loaded, a module makes all of its contained custom operations available to users.
All modules must derive from the ModuleBase class and implement the OnLoad method to perform module initialization. All custom commands, procedures and transactions implemented within a module get registered with Garnet during initialization using this method:
OnLoad(ModuleLoadContext context, string[] args)
Optional arguments passed in to the module are made available through the args parameter.
The ModuleLoadContext exposes the following APIs to register the module and its components:
-
ModuleActionStatus Initialize(string name, uint version)
This must be the first step to register the module with its name and version information. All other registrations must be performed after this. TheModuleActionStatusenum returned indicates the status of module initialization withSuccessstatus confirming successful registration of the module. -
ModuleActionStatus RegisterCommand(string name, CustomRawStringFunctions customFunctions, CommandType type = CommandType.ReadModifyWrite, RespCommandsInfo commandInfo = null, long expirationTicks = 0)Any custom raw string command should be registered using this method with itsname, implementation of the raw string command incustomFunctions,typeindicating whether it is an ReadModifyWrite or Read command (RMW is the default type), optionalcommandInfoto provide details like arity, key specification, acl categories, etc. and the optionalexpirationTicksto govern when the key expires. -
ModuleActionStatus RegisterTransaction(string name, Func<CustomTransactionProcedure> proc, RespCommandsInfo commandInfo = null)Transactions should get registered using this with itsname, a method that returns the tansaction implementationprocand optionalcommandInfo. -
ModuleActionStatus RegisterType(CustomObjectFactory factory)Custom data types are registered using this method withfactorybeing the implementation of the custom object factory that can create instances of the custom object. -
ModuleActionStatus RegisterCommand(string name, CustomObjectFactory factory, CustomObjectFunctions command, CommandType type = CommandType.ReadModifyWrite, RespCommandsInfo commandInfo = null)Custom object commands are registered using this with theirname,factoryinstance registered already using theRegisterType, implementation of the custom object command incommand,typeindicating whether it is an ReadModifyWrite or Read command (RMW is the default type) and optionalcommandInfo. -
ModuleActionStatus RegisterProcedure(string name, CustomProcedure customScriptProc, RespCommandsInfo commandInfo = null)Custom non-transactional procedures are registered using this with theirname, implementation ascustomScriptProcand optionalcommandInfo.
As a reference of an implementation of a module, see the example in playground\SampleModule.