redis/redis-rb · error · ArgumentError

value is required for the MATCH operation

Error message

value is required for the MATCH operation

What it means

arop sends an aggregate operation over an index range. MATCH is a filter that compares each element against a reference value, so the value: keyword is mandatory for it: the operation is upcased and compared to 'MATCH', and a nil value raises ArgumentError 'value is required for the MATCH operation'. Numeric aggregates (SUM/MIN/MAX, etc.) never take a value.

Source

Thrown at lib/redis/commands/arrays.rb:322

      #   redis.arop("foo", 0, 9, :sum)
      #     # => 6.0
      # @example Count elements equal to a value
      #   redis.arop("foo", 0, 9, :match, value: "2")
      #     # => 1
      #
      # @param [String] key
      # @param [Integer] start zero-based index of the first element (inclusive);
      #   the range is always scanned from the lower to the higher index
      # @param [Integer] stop zero-based index of the last element (inclusive)
      # @param [Symbol, String] operation one of `:sum`, `:min`, `:max`,
      #   `:and`, `:or`, `:xor`, `:match`, `:used`
      # @param [String] value the value to compare against (required for `:match`)
      # @return [Float, Integer, nil] the aggregate result — a Float for
      #   `:sum`/`:min`/`:max`, an Integer otherwise; `nil` when no elements
      #   qualify
      def arop(key, start, stop, operation, value: nil)
        operation = operation.to_s.upcase
        raise ArgumentError, "value is required for the MATCH operation" if operation == "MATCH" && value.nil?

        args = [:arop, key, Integer(start), Integer(stop), operation]
        args << value if operation == "MATCH"

        if %w[SUM MIN MAX].include?(operation)
          send_command(args, &Floatify)
        else
          send_command(args)
        end
      end

      # Get metadata about an array.
      #
      # @param [String] key
      # @param [Boolean] full include per-slice statistics
      # @return [Hash{String => Integer, Float}] metadata fields such as
      #   `count`, `len`, `next-insert-index` and `slices`; with `full:` the
      #   `avg-*` slice statistics are returned as `Float`

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass the comparison value: redis.arop(key, start, stop, :match, value: 'x')
  2. If no comparison value exists, use a numeric operation (sum/min/max) instead of match
  3. Validate upfront when the operation is dynamic: raise if it case-matches 'match' and value is nil

Example fix

# before
redis.arop('foo', 0, -1, :match)  # ArgumentError

# after
redis.arop('foo', 0, -1, :match, value: 'target')
Defensive patterns

Strategy: validation

Validate before calling

if operation.to_s.casecmp('match').zero? && value.nil?
  raise ArgumentError, 'value is required for match'
end
redis.arop(key, start, stop, operation, value: value)

Type guard

def needs_value?(operation)
  operation.to_s.casecmp('match').zero?
end

Prevention

When it happens

Trigger: redis.arop('k', 0, -1, :match) or operation: 'match' without value:; forwarding value conditionally (value: cond ? x : nil) so it ends up nil; a generic wrapper that always passes operation but only sometimes value.

Common situations: Aggregation DSLs where the operation is a variable; case/when dispatch that forgets to forward value; porting code from a numeric op to MATCH without adding the value.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23). Data as JSON: /api/errors/8606ae320503ab19. Report an issue: GitHub.