{"record":{"id":"7ea77d580319c6eb","repo":"redis/redis-rb","slug":"wrong-number-of-arguments","errorCode":null,"errorMessage":"wrong number of arguments","messagePattern":"wrong number of arguments","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/arrays.rb","lineNumber":72,"sourceCode":"      # @example With an array (flat, or one array per pair)\n      #   redis.armset(\"foo\", [0, \"a\"], [5, \"f\"])\n      #     # => 2\n      # @example With a Hash\n      #   redis.armset(\"foo\", { 0 => \"a\", 5 => \"f\" })\n      #     # => 2\n      #\n      # @param [String] key\n      # @param [Integer, String, Array<Integer, String>, Array<Array(Integer, String)>,\n      #   Hash{Integer => String}] pairs index-value pairs — as alternating\n      #   index/value arguments, a single flat array, one array per pair, or a Hash\n      # @return [Integer] the number of previously empty slots that were set\n      def armset(key, *pairs)\n        pairs = if pairs.size == 1 && pairs.first.is_a?(Hash)\n          pairs.first.flatten\n        else\n          pairs.flatten(1)\n        end\n        raise ArgumentError, \"wrong number of arguments\" if pairs.empty? || pairs.size.odd?\n\n        args = pairs.each_slice(2).flat_map { |index, value| [Integer(index), value] }\n        send_command([:armset, key, *args])\n      end\n\n      # Get values at multiple indices in an array.\n      #\n      # The reply preserves the order of the requested indices and contains\n      # `nil` for any index that is not set.\n      #\n      # @example\n      #   redis.armget(\"foo\", 0, 1, 9)\n      #     # => [\"a\", \"b\", nil]\n      # @example With an array of indices\n      #   redis.armget(\"foo\", [0, 1, 9])\n      #     # => [\"a\", \"b\", nil]\n      #\n      # @param [String] key","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/arrays.rb#L54-L90","documentation":"Redis#armset builds ARMSET arguments from index/value pairs. After normalizing its arguments (a single Hash is flattened, otherwise flatten(1)) it raises ArgumentError 'wrong number of arguments' when the resulting list is empty (no pairs at all) or has an odd number of elements (a value dangling without its index). This mirrors the server's arity rule, checked client-side before anything is sent.","triggerScenarios":"redis.armset('foo') with no pairs; redis.armset('foo', 0, 'a', 5) — three elements after flatten, odd count; splatting a dynamically built array that was truncated; redis.armset('foo', {}) — the empty Hash flattens to [].","commonSituations":"Programmatic pair construction (each_slice/zip producing an odd-length array); data-driven writes where the last value lost its index; refactors from arset calls that drop a positional argument.","solutions":["Pass complete index/value pairs: armset(key, 0, 'a', 5, 'f') or one array per pair [ [0, 'a'], [5, 'f'] ]","Prefer the Hash form armset(key, { 0 => 'a', 5 => 'f' }) — it cannot produce an odd list","Validate dynamic input before calling: flattened pairs must be non-empty and even-length"],"exampleFix":"# before\nredis.armset('foo', 0, 'a', 5)  # odd pair count: ArgumentError\n\n# after\nredis.armset('foo', 0, 'a', 5, 'f')\nredis.armset('foo', { 0 => 'a', 5 => 'f' })  # Hash form","handlingStrategy":"validation","validationCode":"pairs = pairs.flatten(1)\nraise ArgumentError, 'armset needs index/value pairs' if pairs.empty? || pairs.size.odd?\nredis.armset(key, *pairs)","typeGuard":null,"tryCatchPattern":"begin\n  redis.armset(key, *pairs)\nrescue ArgumentError => e\n  raise ArgumentError, \"bad pairs (#{pairs.inspect}): #{e.message}\"\nend","preventionTips":["Build pairs with each_slice(2) or zip so odd lists are impossible","Prefer the Hash form for sparse index writes","Cover dynamic call sites with a test asserting complete pairs"],"tags":["argument-validation","arrays","arity"],"backgroundTag":"argument-count-mismatch","analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}