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

@@ -693,7 +693,9 @@ func (c cmdable) MemoryUsage(ctx context.Context, key string, samples ...int) *I
args := []interface{}{"memory", "usage", key}
if len(samples) > 0 {
if len(samples) != 1 {
panic("MemoryUsage expects single sample count")
cmd := NewIntCmd(ctx)
cmd.SetErr(errors.New("MemoryUsage expects single sample count"))
return cmd
}
args = append(args, "SAMPLES", samples[0])
}