1
0
mirror of https://github.com/redis/go-redis.git synced 2025-11-04 02:33:24 +03:00

fix(panic): Return error instead of panic from commands (#3568)

Instead of panic in few commands, we can return an error to avoid unexpected panics in application code.
This commit is contained in:
Sourabh
2025-10-28 15:02:34 +05:30
committed by GitHub
parent a3a369b2f5
commit 7be00c8725
4 changed files with 31 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ package redis
import (
"context"
"errors"
"strings"
"time"
@@ -313,7 +314,9 @@ func (c cmdable) ZPopMax(ctx context.Context, key string, count ...int64) *ZSlic
case 1:
args = append(args, count[0])
default:
panic("too many arguments")
cmd := NewZSliceCmd(ctx)
cmd.SetErr(errors.New("too many arguments"))
return cmd
}
cmd := NewZSliceCmd(ctx, args...)
@@ -333,7 +336,9 @@ func (c cmdable) ZPopMin(ctx context.Context, key string, count ...int64) *ZSlic
case 1:
args = append(args, count[0])
default:
panic("too many arguments")
cmd := NewZSliceCmd(ctx)
cmd.SetErr(errors.New("too many arguments"))
return cmd
}
cmd := NewZSliceCmd(ctx, args...)