Module: Valkey::Commands::BitmapCommands
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/bitmap_commands.rb
Overview
this module contains commands related to BITMAP data type.
Instance Method Summary collapse
-
#bitcount(key, start = 0, stop = -1,, scale: nil) ⇒ Integer
Count the number of set bits in a range of the string value stored at key.
- #bitfield(key, *args) ⇒ Object
- #bitfield_ro(key, *args) ⇒ Object
-
#bitop(operation, destkey, *keys) ⇒ Integer
Perform a bitwise operation between strings and store the resulting string in a key.
-
#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.
-
#getbit(key, offset) ⇒ Integer
Returns the bit value at offset in the string value stored at key.
-
#setbit(key, offset, value) ⇒ Integer
Sets or clears the bit at offset in the string value stored at key.
Instance Method Details
#bitcount(key, start = 0, stop = -1,, scale: nil) ⇒ Integer
Count the number of set bits in a range of the string value stored at key.
37 38 39 40 41 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 37 def bitcount(key, start = 0, stop = -1, scale: nil) args = [key, start, stop] args << scale if scale send_command(RequestType::BIT_COUNT, args) end |
#bitfield(key, *args) ⇒ Object
57 58 59 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 57 def bitfield(key, *args) send_command(RequestType::BIT_FIELD, [key] + args.map(&:to_s)) end |
#bitfield_ro(key, *args) ⇒ Object
61 62 63 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 61 def bitfield_ro(key, *args) send_command(RequestType::BIT_FIELD_READ_ONLY, [key] + args.map(&:to_s)) end |
#bitop(operation, destkey, *keys) ⇒ Integer
Perform a bitwise operation between strings and store the resulting string in a key.
49 50 51 52 53 54 55 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 49 def bitop(operation, destkey, *keys) keys.flatten!(1) args = [operation, destkey] args.concat(keys) send_command(RequestType::BIT_OP, args) end |
#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.
75 76 77 78 79 80 81 82 83 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 75 def bitpos(key, bit, start = nil, stop = nil, scale: nil) raise(ArgumentError, 'stop parameter specified without start parameter') if stop && !start args = [key, bit] args << start if start args << stop if stop args << scale if scale send_command(RequestType::BIT_POS, args) end |
#getbit(key, offset) ⇒ Integer
Returns the bit value at offset in the string value stored at key.
25 26 27 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 25 def getbit(key, offset) send_command(RequestType::GET_BIT, [key, offset]) end |
#setbit(key, offset, value) ⇒ Integer
Sets or clears the bit at offset in the string value stored at key.
16 17 18 |
# File 'lib/valkey/commands/bitmap_commands.rb', line 16 def setbit(key, offset, value) send_command(RequestType::SET_BIT, [key, offset, value]) end |