{"record":{"id":"2bfff262391ad79a","repo":"hibiken/asynq","slug":"could-not-cast-v-to-int64","errorCode":null,"errorMessage":"could not cast %v to int64","messagePattern":"could not cast (.+?) to int64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/rdb/inspect.go","lineNumber":1117,"sourceCode":"\nfunc (r *RDB) runAll(zset, qname string) (int64, error) {\n\tif err := r.checkQueueExists(qname); err != nil {\n\t\treturn 0, err\n\t}\n\tkeys := []string{\n\t\tzset,\n\t\tbase.PendingKey(qname),\n\t}\n\targv := []interface{}{\n\t\tbase.TaskKeyPrefix(qname),\n\t}\n\tres, err := runAllCmd.Run(context.Background(), r.client, keys, argv...).Result()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tn, ok := res.(int64)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"could not cast %v to int64\", res)\n\t}\n\tif n == -1 {\n\t\treturn 0, &errors.QueueNotFoundError{Queue: qname}\n\t}\n\treturn n, nil\n}\n\n// ArchiveAllRetryTasks archives all retry tasks from the given queue and\n// returns the number of tasks that were moved.\n// If a queue with the given name doesn't exist, it returns QueueNotFoundError.\nfunc (r *RDB) ArchiveAllRetryTasks(qname string) (int64, error) {\n\tvar op errors.Op = \"rdb.ArchiveAllRetryTasks\"\n\tn, err := r.archiveAll(base.RetryKey(qname), base.ArchivedKey(qname), qname)\n\tif errors.IsQueueNotFound(err) {\n\t\treturn 0, errors.E(op, errors.NotFound, err)\n\t}\n\tif err != nil {\n\t\treturn 0, errors.E(op, errors.Internal, err)","sourceCodeStart":1099,"sourceCodeEnd":1135,"githubUrl":"https://github.com/hibiken/asynq/blob/d135f1439bee74e989b7f9b41ecd542cc87f024a/internal/rdb/inspect.go#L1099-L1135","documentation":"This error is returned by RDB queue-length inspection methods (e.g. queue size queries) when the Lua script (runAllCmd) returns a value that cannot be type-asserted to int64. Redis Lua scripts normally return integers for these counting scripts, so a non-int64 result indicates the script or Redis module behavior deviated from the expected protocol. It is an internal defensive check, not something the caller normally sees.","triggerScenarios":"Calling an RDB method like QueueSize/Stats that runs the runAllCmd Lua script when the script's Reply value comes back as a string, nil, or other non-int64 type — e.g. a modified/overridden script, a Redis-compatible server returning different reply types, or go-redis returning a wrapper type.","commonSituations":"Using a Redis-compatible proxy (Twemproxy, KeyDB, Dragonfly) that changes Lua reply types; running against an unexpected Redis version; a forked/patched internal script file.","solutions":["Verify you are connecting to a standard Redis server that returns integer replies for EVAL scripts","Check that the asynq version's internal Lua scripts were not modified","Log the actual value (%v) to see what type the server returned","Retry the operation; if persistent, report the Redis server/version combination"],"exampleFix":"// before\nres, err := runAllCmd.Run(ctx, r.client, keys, argv...).Result()\nif err != nil { return 0, err }\nn, ok := res.(int64)\nif !ok { return 0, fmt.Errorf(\"could not cast %v to int64\", res) }\n// after\nres, err := runAllCmd.Run(ctx, r.client, keys, argv...).Result()\nif err != nil { return 0, err }\nvar n int64\nswitch v := res.(type) {\ncase int64: n = v\ncase string: n, err = strconv.ParseInt(v, 10, 64)\nif err != nil { return 0, err }\ndefault: return 0, fmt.Errorf(\"could not cast %v to int64\", res)\n}","handlingStrategy":"try-catch","validationCode":"paused, err := inspector.IsPaused(q)\nif err != nil { return err } // ensure Redis is standard and reachable before script calls","typeGuard":"func asInt64(res interface{}) (int64, bool) {\n    n, ok := res.(int64)\n    return n, ok\n}","tryCatchPattern":"n, err := inspector.QueueSize(q)\nif err != nil {\n    if strings.Contains(err.Error(), \"could not cast\") {\n        // unexpected Redis reply; log value and fall back\n    }\n    return err\n}","preventionTips":["Use vanilla Redis, not proxies/forks that alter EVAL replies","Pin asynq and go-redis versions together","Log unexpected script replies for diagnosis","Integration-test against the production Redis version"],"tags":["redis","lua","type-mismatch"],"backgroundTag":"unexpected-response-shape","analyzedSha":"d135f1439bee74e989b7f9b41ecd542cc87f024a","analyzedAt":"2026-09-07T19:02:34.660Z","contentChangedAt":"2026-09-07T19:02:34.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}