redis/go-redis · error

redis: ModuleLoadex nil config

Error message

redis: ModuleLoadex nil config

What it means

Error produced by ModuleLoadex (commands.go:895) when the *ModuleLoadexConfig argument is nil. Instead of panicking on a nil dereference while building the MODULE LOADEX arguments, the method short-circuits and returns a StringCmd with this error set. Fix: pass a valid &ModuleLoadexConfig{Path: ...} with at least the module Path populated.

Source

Thrown at commands.go:895

func (c *ModuleLoadexConfig) toArgs() []interface{} {
	args := make([]interface{}, 3, 3+len(c.Conf)*3+len(c.Args)*2)
	args[0] = "MODULE"
	args[1] = "LOADEX"
	args[2] = c.Path
	for k, v := range c.Conf {
		args = append(args, "CONFIG", k, v)
	}
	for _, arg := range c.Args {
		args = append(args, "ARGS", arg)
	}
	return args
}

// ModuleLoadex Redis `MODULE LOADEX path [CONFIG name value [CONFIG name value ...]] [ARGS args [args ...]]` command.
func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd {
	if conf == nil {
		cmd := NewStringCmd(ctx)
		cmd.SetErr(errors.New("redis: ModuleLoadex nil config"))
		return cmd
	}
	cmd := NewStringCmd(ctx, conf.toArgs()...)
	_ = c(ctx, cmd)
	return cmd
}

/*
Monitor - represents a Redis MONITOR command, allowing the user to capture
and process all commands sent to a Redis server. This mimics the behavior of
MONITOR in the redis-cli.

Notes:
- Using MONITOR blocks the connection to the server for itself. It needs a dedicated connection
- The user should create a channel of type string
- This runs concurrently in the background. Trigger via the Start and Stop functions
See further: Redis MONITOR command: https://redis.io/commands/monitor
*/

View on GitHub (pinned to c5cad058c7)

Solutions

  1. Construct a config: &redis.ModuleLoadexConfig{Path: "/path/to/module.so", ...}.
  2. Nil-check the config before calling.
  3. Ensure any config-producing function returns a valid pointer or is handled on error.

Example fix

// before
var conf *redis.ModuleLoadexConfig
rdb.ModuleLoadex(ctx, conf)
// after
conf := &redis.ModuleLoadexConfig{Path: "/usr/lib/redis/modules/module.so"}
rdb.ModuleLoadex(ctx, conf)
Defensive patterns

Strategy: validation

Validate before calling

if conf == nil {
    return errors.New("ModuleLoadexConfig must be provided")
}
rdb.ModuleLoadex(ctx, conf)

Type guard

func validLoadex(conf *redis.ModuleLoadexConfig) bool {
    return conf != nil && conf.Path != ""
}

Prevention

When it happens

Trigger: Calling rdb.ModuleLoadex(ctx, nil).

Common situations: Passing a config variable that was declared but never initialized (var conf *ModuleLoadexConfig); a factory returning nil on failure whose result is passed straight through.

Related errors


AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01). Data as JSON: /api/errors/dbcc9315f352bfb9. Report an issue: GitHub.