forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: add BITCOUNT command (valkey-io#1592)
- Loading branch information
1 parent
d690c1b
commit f017e0a
Showing
7 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 | ||
from enum import Enum | ||
from typing import List, Optional | ||
|
||
|
||
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: Redis 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. | ||
""" | ||
|
||
|
||
class OffsetOptions: | ||
def __init__( | ||
self, start: int, end: int, index_type: Optional[BitmapIndexType] = None | ||
): | ||
""" | ||
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. | ||
Args: | ||
start (int): The starting offset index. | ||
end (int): The ending offset index. | ||
index_type (Optional[BitmapIndexType]): The index offset type. This option can only be specified if you are | ||
using Redis 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. | ||
""" | ||
self.start = start | ||
self.end = end | ||
self.index_type = index_type | ||
|
||
def to_args(self) -> List[str]: | ||
args = [str(self.start), str(self.end)] | ||
if self.index_type is not None: | ||
args.append(self.index_type.value) | ||
|
||
return args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters