Module: Valkey::Commands::ModuleCommands

Included in:
Valkey::Commands
Defined in:
lib/valkey/commands/module_commands.rb

Overview

This module contains commands related to Valkey Modules.

Instance Method Summary collapse

Instance Method Details

#module(subcommand, *args, **options) ⇒ Object

Control module registry (convenience method).

Examples:

List all modules

valkey.module(:list)
  # => [...]

Load a module

valkey.module(:load, "/path/to/mymodule.so")
  # => "OK"

Unload a module

valkey.module(:unload, "mymodule")
  # => "OK"

Load a module with extended options

valkey.module(:loadex, "/path/to/mymodule.so", configs: {"param1" => "value1"})
  # => "OK"

Parameters:

  • subcommand (String, Symbol)

    the subcommand (list, load, unload, loadex)

  • args (Array)

    arguments for the subcommand

  • options (Hash)

    options for the subcommand

Returns:

  • (Object)

    depends on subcommand



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/valkey/commands/module_commands.rb', line 112

def module(subcommand, *args, **options)
  subcommand = subcommand.to_s.downcase

  if args.empty? && options.empty?
    send("module_#{subcommand}")
  elsif options.empty?
    send("module_#{subcommand}", *args)
  else
    send("module_#{subcommand}", *args, **options)
  end
end

#module_listArray<Hash>

List all loaded modules.

Examples:

List all modules

valkey.module_list
  # => [{"name" => "mymodule", "ver" => 1, ...}]

Returns:

  • (Array<Hash>)

    array of module information

See Also:



19
20
21
# File 'lib/valkey/commands/module_commands.rb', line 19

def module_list
  send_command(RequestType::MODULE_LIST)
end

#module_load(path, *args) ⇒ String

Load a module.

Examples:

Load a module

valkey.module_load("/path/to/mymodule.so")
  # => "OK"

Load a module with arguments

valkey.module_load("/path/to/mymodule.so", "arg1", "arg2")
  # => "OK"

Parameters:

  • path (String)

    the path to the module file

  • args (Array<String>)

    optional arguments to pass to the module

Returns:

  • (String)

    “OK”

See Also:



37
38
39
40
# File 'lib/valkey/commands/module_commands.rb', line 37

def module_load(path, *args)
  command_args = [path] + args
  send_command(RequestType::MODULE_LOAD, command_args)
end

#module_loadex(path, configs: {}, args: []) ⇒ String

Load a module with extended options.

Examples:

Load a module with CONFIG option

valkey.module_loadex("/path/to/mymodule.so", configs: {"param1" => "value1"})
  # => "OK"

Load a module with ARGS option

valkey.module_loadex("/path/to/mymodule.so", args: ["arg1", "arg2"])
  # => "OK"

Load a module with both CONFIG and ARGS

valkey.module_loadex("/path/to/mymodule.so", configs: {"param1" => "value1"}, args: ["arg1"])
  # => "OK"

Parameters:

  • path (String)

    the path to the module file

  • configs (Hash) (defaults to: {})

    configuration parameters as key-value pairs

  • args (Array<String>) (defaults to: [])

    optional arguments to pass to the module

Returns:

  • (String)

    “OK”

See Also:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/valkey/commands/module_commands.rb', line 74

def module_loadex(path, configs: {}, args: [])
  command_args = [path]

  unless configs.empty?
    command_args << "CONFIG"
    configs.each do |key, value|
      command_args << key.to_s
      command_args << value.to_s
    end
  end

  unless args.empty?
    command_args << "ARGS"
    command_args.concat(args)
  end

  send_command(RequestType::MODULE_LOAD_EX, command_args)
end

#module_unload(name) ⇒ String

Unload a module.

Examples:

Unload a module

valkey.module_unload("mymodule")
  # => "OK"

Parameters:

  • name (String)

    the module name to unload

Returns:

  • (String)

    “OK”

See Also:



52
53
54
# File 'lib/valkey/commands/module_commands.rb', line 52

def module_unload(name)
  send_command(RequestType::MODULE_UNLOAD, [name])
end