mirror of
https://github.com/redis/go-redis.git
synced 2026-10-28 08:24:54 +08:00
fix(command): return error on ModuleLoadex with nil config (#3916)
Calling ModuleLoadex(nil) previously panicked in toArgs. Return a sticky command error instead.
This commit is contained in:
1 parent
ee2703fd5e
commit
f745ff4409
2 files changed
+22
No files matched your search
@@ -798,6 +798,11 @@ func (c *ModuleLoadexConfig) toArgs() []interface{} {
|
||||
|
||||
// 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
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestModuleLoadexNilConfig(t *testing.T) {
|
||||
rdb := NewClient(&Options{Addr: "localhost:6379"})
|
||||
cmd := rdb.ModuleLoadex(context.Background(), nil)
|
||||
if cmd.Err() == nil {
|
||||
t.Fatal("expected error for nil config")
|
||||
}
|
||||
if cmd.Err().Error() != "redis: ModuleLoadex nil config" {
|
||||
t.Fatalf("got %v", cmd.Err())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user