Skip to content

glide_shared.commands.bitmap

BitmapIndexType

Bases: Enum

Enumeration specifying if index arguments are BYTE indexes or BIT indexes. Can be specified in OffsetOptions, which is an optional argument to the BITCOUNT command.

Since: Valkey version 7.0.0.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class BitmapIndexType(Enum):
    """
    Enumeration specifying if index arguments are BYTE indexes or BIT indexes. Can be specified in `OffsetOptions`,
    which is an optional argument to the `BITCOUNT` command.

    Since: Valkey version 7.0.0.
    """

    BYTE = "BYTE"
    """
    Specifies that indexes provided to `OffsetOptions` are byte indexes.
    """
    BIT = "BIT"
    """
    Specifies that indexes provided to `OffsetOptions` are bit indexes.
    """

BYTE = 'BYTE' class-attribute instance-attribute

Specifies that indexes provided to OffsetOptions are byte indexes.

BIT = 'BIT' class-attribute instance-attribute

Specifies that indexes provided to OffsetOptions are bit indexes.

OffsetOptions

Represents offsets specifying a string interval to analyze in the BITCOUNT command. The offsets are zero-based indexes, with 0 being the first index of the string, 1 being the next index and so on. The offsets can also be negative numbers indicating offsets starting at the end of the string, with -1 being the last index of the string, -2 being the penultimate, and so on.

Attributes:

Name Type Description
start int

The starting offset index.

end Optional[int]

The ending offset index. Optional since Valkey version 8.0.0 and above for the BITCOUNT command. If not provided, it will default to the end of the string.

index_type Optional[BitmapIndexType]

The index offset type. This option can only be specified if you are using Valkey version 7.0.0 or above. Could be either BitmapIndexType.BYTE or BitmapIndexType.BIT. If no index type is provided, the indexes will be assumed to be byte indexes.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class OffsetOptions:
    """
    Represents offsets specifying a string interval to analyze in the `BITCOUNT` command. The offsets are
    zero-based indexes, with `0` being the first index of the string, `1` being the next index and so on.
    The offsets can also be negative numbers indicating offsets starting at the end of the string, with `-1` being
    the last index of the string, `-2` being the penultimate, and so on.

    Attributes:
        start (int): The starting offset index.
        end (Optional[int]): The ending offset index. Optional since Valkey version 8.0.0 and above for the BITCOUNT
            command. If not provided, it will default to the end of the string.
        index_type (Optional[BitmapIndexType]): The index offset type. This option can only be specified if you are
            using Valkey version 7.0.0 or above. Could be either `BitmapIndexType.BYTE` or `BitmapIndexType.BIT`.
            If no index type is provided, the indexes will be assumed to be byte indexes.
    """

    def __init__(
        self,
        start: int,
        end: Optional[int] = None,
        index_type: Optional[BitmapIndexType] = None,
    ):
        self.start = start
        self.end = end
        self.index_type = index_type

    def to_args(self) -> List[str]:
        args = [str(self.start)]
        if self.end:
            args.append(str(self.end))
        if self.index_type is not None:
            args.append(self.index_type.value)

        return args

BitwiseOperation

Bases: Enum

Enumeration defining the bitwise operation to use in the BITOP command. Specifies the bitwise operation to perform between the passed in keys.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
61
62
63
64
65
66
67
68
69
70
class BitwiseOperation(Enum):
    """
    Enumeration defining the bitwise operation to use in the `BITOP` command. Specifies the bitwise operation to
    perform between the passed in keys.
    """

    AND = "AND"
    OR = "OR"
    XOR = "XOR"
    NOT = "NOT"

BitEncoding

Bases: ABC

Abstract Base Class used to specify a signed or unsigned argument encoding for the BITFIELD or BITFIELD_RO commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
73
74
75
76
77
78
79
80
81
82
83
84
85
class BitEncoding(ABC):
    """
    Abstract Base Class used to specify a signed or unsigned argument encoding for the `BITFIELD` or `BITFIELD_RO`
    commands.
    """

    @abstractmethod
    def to_arg(self) -> str:
        """
        Returns the encoding as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
        commands.
        """
        pass

to_arg() abstractmethod

Returns the encoding as a string argument to be used in the BITFIELD or BITFIELD_RO commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
79
80
81
82
83
84
85
@abstractmethod
def to_arg(self) -> str:
    """
    Returns the encoding as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
    commands.
    """
    pass

SignedEncoding

Bases: BitEncoding

Represents a signed argument encoding. Must be less than 65 bits long.

Attributes:

Name Type Description
encoding_length int

The bit size of the encoding.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class SignedEncoding(BitEncoding):
    """
    Represents a signed argument encoding. Must be less than 65 bits long.

    Attributes:
        encoding_length (int): The bit size of the encoding.
    """

    #: Prefix specifying that the encoding is signed.
    SIGNED_ENCODING_PREFIX = "i"

    def __init__(self, encoding_length: int):
        self._encoding = f"{self.SIGNED_ENCODING_PREFIX}{str(encoding_length)}"

    def to_arg(self) -> str:
        return self._encoding

UnsignedEncoding

Bases: BitEncoding

Represents an unsigned argument encoding. Must be less than 64 bits long.

Attributes:

Name Type Description
encoding_length int

The bit size of the encoding.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class UnsignedEncoding(BitEncoding):
    """
    Represents an unsigned argument encoding. Must be less than 64 bits long.

    Attributes:
        encoding_length (int): The bit size of the encoding.
    """

    #: Prefix specifying that the encoding is unsigned.
    UNSIGNED_ENCODING_PREFIX = "u"

    def __init__(self, encoding_length: int):
        self._encoding = f"{self.UNSIGNED_ENCODING_PREFIX}{str(encoding_length)}"

    def to_arg(self) -> str:
        return self._encoding

BitFieldOffset

Bases: ABC

Abstract Base Class representing an offset for an array of bits for the BITFIELD or BITFIELD_RO commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
124
125
126
127
128
129
130
131
132
133
class BitFieldOffset(ABC):
    """Abstract Base Class representing an offset for an array of bits for the `BITFIELD` or `BITFIELD_RO` commands."""

    @abstractmethod
    def to_arg(self) -> str:
        """
        Returns the offset as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
        commands.
        """
        pass

to_arg() abstractmethod

Returns the offset as a string argument to be used in the BITFIELD or BITFIELD_RO commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
127
128
129
130
131
132
133
@abstractmethod
def to_arg(self) -> str:
    """
    Returns the offset as a string argument to be used in the `BITFIELD` or `BITFIELD_RO`
    commands.
    """
    pass

BitOffset

Bases: BitFieldOffset

Represents an offset in an array of bits for the BITFIELD or BITFIELD_RO commands. Must be greater than or equal to 0.

For example, if we have the binary 01101001 with offset of 1 for an unsigned encoding of size 4, then the value is 13 from 0(1101)001.

Attributes:

Name Type Description
offset int

The bit index offset in the array of bits.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class BitOffset(BitFieldOffset):
    """
    Represents an offset in an array of bits for the `BITFIELD` or `BITFIELD_RO` commands. Must be greater than or
    equal to 0.

    For example, if we have the binary `01101001` with offset of 1 for an unsigned encoding of size 4, then the value
    is 13 from `0(1101)001`.

    Attributes:
        offset (int): The bit index offset in the array of bits.
    """

    def __init__(self, offset: int):
        self._offset = str(offset)

    def to_arg(self) -> str:
        return self._offset

BitOffsetMultiplier

Bases: BitFieldOffset

Represents an offset in an array of bits for the BITFIELD or BITFIELD_RO commands. The bit offset index is calculated as the numerical value of the offset multiplied by the encoding value. Must be greater than or equal to 0.

For example, if we have the binary 01101001 with offset multiplier of 1 for an unsigned encoding of size 4, then the value is 9 from 0110(1001).

Attributes:

Name Type Description
offset int

The offset in the array of bits, which will be multiplied by the encoding value to get the final bit index offset.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class BitOffsetMultiplier(BitFieldOffset):
    """
    Represents an offset in an array of bits for the `BITFIELD` or `BITFIELD_RO` commands. The bit offset index is
    calculated as the numerical value of the offset multiplied by the encoding value. Must be greater than or equal
    to 0.

    For example, if we have the binary 01101001 with offset multiplier of 1 for an unsigned encoding of size 4, then
    the value is 9 from `0110(1001)`.

    Attributes:
        offset (int): The offset in the array of bits, which will be multiplied by the encoding value to get the
            final bit index offset.
    """

    #: Prefix specifying that the offset uses an encoding multiplier.
    OFFSET_MULTIPLIER_PREFIX = "#"

    def __init__(self, offset: int):
        self._offset = f"{self.OFFSET_MULTIPLIER_PREFIX}{str(offset)}"

    def to_arg(self) -> str:
        return self._offset

BitFieldSubCommands

Bases: ABC

Abstract Base Class representing subcommands for the BITFIELD or BITFIELD_RO commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
179
180
181
182
183
184
185
186
187
class BitFieldSubCommands(ABC):
    """Abstract Base Class representing subcommands for the `BITFIELD` or `BITFIELD_RO` commands."""

    @abstractmethod
    def to_args(self) -> List[str]:
        """
        Returns the subcommand as a list of string arguments to be used in the `BITFIELD` or `BITFIELD_RO` commands.
        """
        pass

to_args() abstractmethod

Returns the subcommand as a list of string arguments to be used in the BITFIELD or BITFIELD_RO commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
182
183
184
185
186
187
@abstractmethod
def to_args(self) -> List[str]:
    """
    Returns the subcommand as a list of string arguments to be used in the `BITFIELD` or `BITFIELD_RO` commands.
    """
    pass

BitFieldGet

Bases: BitFieldSubCommands

Represents the "GET" subcommand for getting a value in the binary representation of the string stored in key.

Attributes:

Name Type Description
encoding BitEncoding

The bit encoding for the subcommand.

offset BitFieldOffset

The offset in the array of bits from which to get the value.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
class BitFieldGet(BitFieldSubCommands):
    """
    Represents the "GET" subcommand for getting a value in the binary representation of the string stored in `key`.

    Attributes:
        encoding (BitEncoding): The bit encoding for the subcommand.
        offset (BitFieldOffset): The offset in the array of bits from which to get the value.
    """

    #: "GET" subcommand string for use in the `BITFIELD` or `BITFIELD_RO` commands.
    GET_COMMAND_STRING = "GET"

    def __init__(self, encoding: BitEncoding, offset: BitFieldOffset):
        self._encoding = encoding
        self._offset = offset

    def to_args(self) -> List[str]:
        return [self.GET_COMMAND_STRING, self._encoding.to_arg(), self._offset.to_arg()]

BitFieldSet

Bases: BitFieldSubCommands

Represents the "SET" subcommand for setting bits in the binary representation of the string stored in key.

Parameters:

Name Type Description Default
encoding BitEncoding

The bit encoding for the subcommand.

required
offset BitOffset

The offset in the array of bits where the value will be set.

required
value int

The value to set the bits in the binary value to.

required
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
class BitFieldSet(BitFieldSubCommands):
    """
    Represents the "SET" subcommand for setting bits in the binary representation of the string stored in `key`.

    Args:
        encoding (BitEncoding): The bit encoding for the subcommand.
        offset (BitOffset): The offset in the array of bits where the value will be set.
        value (int): The value to set the bits in the binary value to.
    """

    #: "SET" subcommand string for use in the `BITFIELD` command.
    SET_COMMAND_STRING = "SET"

    def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, value: int):
        self._encoding = encoding
        self._offset = offset
        self._value = value

    def to_args(self) -> List[str]:
        return [
            self.SET_COMMAND_STRING,
            self._encoding.to_arg(),
            self._offset.to_arg(),
            str(self._value),
        ]

BitFieldIncrBy

Bases: BitFieldSubCommands

Represents the "INCRBY" subcommand for increasing or decreasing bits in the binary representation of the string stored in key.

Attributes:

Name Type Description
encoding BitEncoding

The bit encoding for the subcommand.

offset BitOffset

The offset in the array of bits where the value will be incremented.

increment int

The value to increment the bits in the binary value by.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
class BitFieldIncrBy(BitFieldSubCommands):
    """
    Represents the "INCRBY" subcommand for increasing or decreasing bits in the binary representation of the
    string stored in `key`.

    Attributes:
        encoding (BitEncoding): The bit encoding for the subcommand.
        offset (BitOffset): The offset in the array of bits where the value will be incremented.
        increment (int): The value to increment the bits in the binary value by.
    """

    #: "INCRBY" subcommand string for use in the `BITFIELD` command.
    INCRBY_COMMAND_STRING = "INCRBY"

    def __init__(self, encoding: BitEncoding, offset: BitFieldOffset, increment: int):
        self._encoding = encoding
        self._offset = offset
        self._increment = increment

    def to_args(self) -> List[str]:
        return [
            self.INCRBY_COMMAND_STRING,
            self._encoding.to_arg(),
            self._offset.to_arg(),
            str(self._increment),
        ]

BitOverflowControl

Bases: Enum

Enumeration specifying bit overflow controls for the BITFIELD command.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
class BitOverflowControl(Enum):
    """
    Enumeration specifying bit overflow controls for the `BITFIELD` command.
    """

    WRAP = "WRAP"
    """
    Performs modulo when overflows occur with unsigned encoding. When overflows occur with signed encoding, the value
    restarts at the most negative value. When underflows occur with signed encoding, the value restarts at the most
    positive value.
    """
    SAT = "SAT"
    """
    Underflows remain set to the minimum value, and overflows remain set to the maximum value.
    """
    FAIL = "FAIL"
    """
    Returns `None` when overflows occur.
    """

WRAP = 'WRAP' class-attribute instance-attribute

Performs modulo when overflows occur with unsigned encoding. When overflows occur with signed encoding, the value restarts at the most negative value. When underflows occur with signed encoding, the value restarts at the most positive value.

SAT = 'SAT' class-attribute instance-attribute

Underflows remain set to the minimum value, and overflows remain set to the maximum value.

FAIL = 'FAIL' class-attribute instance-attribute

Returns None when overflows occur.

BitFieldOverflow

Bases: BitFieldSubCommands

Represents the "OVERFLOW" subcommand that determines the result of the "SET" or "INCRBY" BITFIELD subcommands when an underflow or overflow occurs.

Attributes:

Name Type Description
overflow_control BitOverflowControl

The desired overflow behavior.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/bitmap.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
class BitFieldOverflow(BitFieldSubCommands):
    """
    Represents the "OVERFLOW" subcommand that determines the result of the "SET" or "INCRBY" `BITFIELD` subcommands
    when an underflow or overflow occurs.

    Attributes:
        overflow_control (BitOverflowControl): The desired overflow behavior.
    """

    #: "OVERFLOW" subcommand string for use in the `BITFIELD` command.
    OVERFLOW_COMMAND_STRING = "OVERFLOW"

    def __init__(self, overflow_control: BitOverflowControl):
        self._overflow_control = overflow_control

    def to_args(self) -> List[str]:
        return [self.OVERFLOW_COMMAND_STRING, self._overflow_control.value]