Implemented LoadModules method to load external modules at runtime.

Implemented UnloadModules method to remove modules at runtime.
Implemented ListModules method to list the current loaded modules.
Implemented "MODULE LOAD", "MODULE UNLOAD", and "MODULE LIST" commands.
This commit is contained in:
Kelvin Clement Mwinuka
2024-05-03 11:57:21 +08:00
parent 276ca0fb63
commit 0f6ae1c8ac
14 changed files with 289 additions and 56 deletions

View File

@@ -231,6 +231,8 @@ func (server *EchoVault) RewriteAOF() (string, error) {
//
// "command <command> already exists" - If a command with the same command name as the passed command already exists.
func (server *EchoVault) AddCommand(command CommandOptions) error {
server.commandsRWMut.Lock()
defer server.commandsRWMut.Unlock()
// Check if command already exists
for _, c := range server.commands {
if strings.EqualFold(c.Command, command.Command) {
@@ -398,6 +400,9 @@ func (server *EchoVault) ExecuteCommand(command ...string) ([]byte, error) {
//
// `command` - ...string.
func (server *EchoVault) RemoveCommand(command ...string) {
server.commandsRWMut.Lock()
defer server.commandsRWMut.Unlock()
switch len(command) {
case 1:
// Remove command