{"id":"1ed528312683c898","repo":"go-redis/redis","slug":"memoryusage-expects-single-sample-count","errorCode":null,"errorMessage":"MemoryUsage expects single sample count","messagePattern":"MemoryUsage expects single sample count","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands.go","lineNumber":856,"sourceCode":"\nfunc (c cmdable) Time(ctx context.Context) *TimeCmd {\n\tcmd := NewTimeCmd(ctx, \"time\")\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\nfunc (c cmdable) DebugObject(ctx context.Context, key string) *StringCmd {\n\tcmd := NewStringCmd(ctx, \"debug\", \"object\", key)\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\nfunc (c cmdable) MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd {\n\targs := []interface{}{\"memory\", \"usage\", key}\n\tif len(samples) > 0 {\n\t\tif len(samples) != 1 {\n\t\t\tcmd := NewIntCmd(ctx)\n\t\t\tcmd.SetErr(errors.New(\"MemoryUsage expects single sample count\"))\n\t\t\treturn cmd\n\t\t}\n\t\targs = append(args, \"SAMPLES\", samples[0])\n\t}\n\tcmd := NewIntCmd(ctx, args...)\n\tcmd.SetFirstKeyPos(2)\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\n//------------------------------------------------------------------------------\n\n// ModuleLoadexConfig struct is used to specify the arguments for the MODULE LOADEX command of redis.\n// `MODULE LOADEX path [CONFIG name value [CONFIG name value ...]] [ARGS args [args ...]]`\ntype ModuleLoadexConfig struct {\n\tPath string\n\tConf map[string]interface{}\n\tArgs []interface{}","sourceCodeStart":838,"sourceCodeEnd":874,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/commands.go#L838-L874","documentation":"Error \"MemoryUsage expects single sample count\" thrown in go-redis/redis.","triggerScenarios":"Thrown at commands.go:856 when the library encounters an invalid state.","commonSituations":"Guard variadic count arguments with a length check before the call.","solutions":["Pass a single sample count value to MemoryUsage (or none), not several","Use the typed MemoryUsage signature instead of spreading a slice"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}