Method: Redis::Commands::Bitmaps#bitpos

Defined in:
lib/redis/commands/bitmaps.rb

#bitpos(key, bit, start = nil, stop = nil, scale: nil) ⇒ Integer

Return the position of the first bit set to 1 or 0 in a string.

Parameters:

  • key (String)
  • bit (Integer)

    whether to look for the first 1 or 0 bit

  • start (Integer) (defaults to: nil)

    start index

  • stop (Integer) (defaults to: nil)

    stop index

  • scale (String, Symbol) (defaults to: nil)

    the scale of the offset range e.g. ‘BYTE’ - interpreted as a range of bytes, ‘BIT’ - interpreted as a range of bits

Returns:

  • (Integer)

    the position of the first 1/0 bit. -1 if looking for 1 and it is not found or start and stop are given.

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
69
70
# File 'lib/redis/commands/bitmaps.rb', line 62

def bitpos(key, bit, start = nil, stop = nil, scale: nil)
  raise(ArgumentError, 'stop parameter specified without start parameter') if stop && !start

  command = [:bitpos, key, bit]
  command << start if start
  command << stop if stop
  command << scale if scale
  send_command(command)
end