redis/redis-rb · error · ArgumentError

only one of :by_score or :by_lex can be specified

Error message

only one of :by_score or :by_lex can be specified

What it means

Error "only one of :by_score or :by_lex can be specified" thrown in redis/redis-rb.

Source

Thrown at lib/redis/commands/sorted_sets.rb:370

      #
      # @param [String] key
      # @param [Integer] start start index
      # @param [Integer] stop stop index
      # @param [Hash] options
      #   - `:by_score => false`: return members by score
      #   - `:by_lex => false`: return members by lexicographical ordering
      #   - `:rev => false`: reverse the ordering, from highest to lowest
      #   - `:limit => [offset, count]`: skip `offset` members, return a maximum of
      #   `count` members
      #   - `:with_scores => true`: include scores in output
      #
      # @return [Array<String>, Array<[String, Float]>]
      #   - when `:with_scores` is not specified, an array of members
      #   - when `:with_scores` is specified, an array with `[member, score]` pairs
      def zrange(key, start, stop, byscore: false, by_score: byscore, bylex: false, by_lex: bylex,
                 rev: false, limit: nil, withscores: false, with_scores: withscores)
        if by_score && by_lex
          raise ArgumentError, "only one of :by_score or :by_lex can be specified"
        end

        args = [:zrange, key, start, stop]

        if by_score
          args << "BYSCORE"
        elsif by_lex
          args << "BYLEX"
        end

        args << "REV" if rev

        if limit
          args << "LIMIT"
          args.concat(limit.map { |l| Integer(l) })
        end

        if with_scores

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass only one of :by_score or :by_lex.
  2. Choose by_score for score ranges or by_lex for lexicographical ranges, and drop the other flag.

When it happens

Trigger: Thrown at lib/redis/commands/sorted_sets.rb:370 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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