redis/redis-rb · error · ArgumentError

count argument must be specified

Error message

count argument must be specified

What it means

Error "count argument must be specified" thrown in redis/redis-rb.

Source

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

      #   redis.zrandmember("zset", 2)
      #     # => ["a", "b"]
      # @example Get multiple random members with scores
      #   redis.zrandmember("zset", 2, with_scores: true)
      #     # => [["a", 2.0], ["b", 3.0]]
      #
      # @param [String] key
      # @param [Integer] count
      # @param [Hash] options
      #   - `:with_scores => true`: include scores in output
      #
      # @return [nil, String, Array<String>, Array<[String, Float]>]
      #   - when `key` does not exist or set is empty, `nil`
      #   - when `count` is not specified, a member
      #   - when `count` is specified and `:with_scores` is not specified, an array of members
      #   - when `:with_scores` is specified, an array with `[member, score]` pairs
      def zrandmember(key, count = nil, withscores: false, with_scores: withscores)
        if with_scores && count.nil?
          raise ArgumentError, "count argument must be specified"
        end

        args = [:zrandmember, key]
        args << Integer(count) if count

        if with_scores
          args << "WITHSCORES"
          block = FloatifyPairs
        end

        send_command(args, &block)
      end

      # Return a range of members in a sorted set, by index, score or lexicographical ordering.
      #
      # @example Retrieve all members from a sorted set, by index
      #   redis.zrange("zset", 0, -1)
      #     # => ["a", "b"]

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass the count: keyword argument; this command variant requires an explicit count.
  2. Use the non-count variant of the command if you do not want to limit results.

When it happens

Trigger: Thrown at lib/redis/commands/sorted_sets.rb:330 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/78fb79fe1b956f33. Report an issue: GitHub.