Skip to content

glide_shared.commands.sorted_set

InfBound

Bases: Enum

Enumeration representing numeric and lexicographic positive and negative infinity bounds for sorted set.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class InfBound(Enum):
    """
    Enumeration representing numeric and lexicographic positive and negative infinity bounds for sorted set.
    """

    POS_INF = {"score_arg": "+inf", "lex_arg": "+"}
    """
    Positive infinity bound for sorted set.

    `score_arg`: represents numeric positive infinity (+inf).

    `lex_arg`: represents lexicographic positive infinity (+).
    """
    NEG_INF = {"score_arg": "-inf", "lex_arg": "-"}
    """
    Negative infinity bound for sorted set.

    `score_arg`: represents numeric negative infinity (-inf).

    `lex_arg`: represents lexicographic negative infinity (-).
    """

POS_INF = {'score_arg': '+inf', 'lex_arg': '+'} class-attribute instance-attribute

Positive infinity bound for sorted set.

score_arg: represents numeric positive infinity (+inf).

lex_arg: represents lexicographic positive infinity (+).

NEG_INF = {'score_arg': '-inf', 'lex_arg': '-'} class-attribute instance-attribute

Negative infinity bound for sorted set.

score_arg: represents numeric negative infinity (-inf).

lex_arg: represents lexicographic negative infinity (-).

AggregationType

Bases: Enum

Enumeration representing aggregation types for ZINTERSTORE and ZUNIONSTORE sorted set commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class AggregationType(Enum):
    """
    Enumeration representing aggregation types for `ZINTERSTORE` and `ZUNIONSTORE` sorted set commands.
    """

    SUM = "SUM"
    """
    Represents aggregation by summing the scores of elements across inputs where they exist.
    """
    MIN = "MIN"
    """
    Represents aggregation by selecting the minimum score of an element across inputs where it exists.
    """
    MAX = "MAX"
    """
    Represents aggregation by selecting the maximum score of an element across inputs where it exists.
    """

SUM = 'SUM' class-attribute instance-attribute

Represents aggregation by summing the scores of elements across inputs where they exist.

MIN = 'MIN' class-attribute instance-attribute

Represents aggregation by selecting the minimum score of an element across inputs where it exists.

MAX = 'MAX' class-attribute instance-attribute

Represents aggregation by selecting the maximum score of an element across inputs where it exists.

ScoreFilter

Bases: Enum

Defines which elements to pop from a sorted set.

ScoreFilter is a mandatory option for ZMPOP and BZMPOP.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class ScoreFilter(Enum):
    """
    Defines which elements to pop from a sorted set.

    ScoreFilter is a mandatory option for [ZMPOP](https://valkey.io/commands/zmpop)
    and [BZMPOP](https://valkey.io/commands/bzmpop).
    """

    MIN = "MIN"
    """
    Pop elements with the lowest scores.
    """
    MAX = "MAX"
    """
    Pop elements with the highest scores.
    """

MIN = 'MIN' class-attribute instance-attribute

Pop elements with the lowest scores.

MAX = 'MAX' class-attribute instance-attribute

Pop elements with the highest scores.

ScoreBoundary

Represents a specific numeric score boundary in a sorted set.

Parameters:

Name Type Description Default
value float

The score value.

required
is_inclusive bool

Whether the score value is inclusive. Defaults to True.

True
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
70
71
72
73
74
75
76
77
78
79
80
81
class ScoreBoundary:
    """
    Represents a specific numeric score boundary in a sorted set.

    Args:
        value (float): The score value.
        is_inclusive (bool): Whether the score value is inclusive. Defaults to True.
    """

    def __init__(self, value: float, is_inclusive: bool = True):
        # Convert the score boundary to Valkey protocol format
        self.value = str(value) if is_inclusive else f"({value}"

LexBoundary

Represents a specific lexicographic boundary in a sorted set.

Parameters:

Name Type Description Default
value str

The lex value.

required
is_inclusive bool

Whether the score value is inclusive. Defaults to True.

True
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
84
85
86
87
88
89
90
91
92
93
94
95
class LexBoundary:
    """
    Represents a specific lexicographic boundary in a sorted set.

    Args:
        value (str): The lex value.
        is_inclusive (bool): Whether the score value is inclusive. Defaults to True.
    """

    def __init__(self, value: str, is_inclusive: bool = True):
        # Convert the lexicographic boundary to Valkey protocol format
        self.value = f"[{value}" if is_inclusive else f"({value}"

RangeByIndex

Represents a range by index (rank) in a sorted set.

The start and end arguments represent zero-based indexes.

Attributes:

Name Type Description
start int

The start index of the range.

end int

The end index of the range.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class RangeByIndex:
    """
    Represents a range by index (rank) in a sorted set.

    The `start` and `end` arguments represent zero-based indexes.

    Attributes:
        start (int): The start index of the range.
        end (int): The end index of the range.
    """

    def __init__(self, start: int, end: int):
        self.start = start
        self.end = end

RangeByScore

Represents a range by score in a sorted set.

The start and end arguments represent score boundaries.

Attributes:

Name Type Description
start Union[InfBound, ScoreBoundary]

The start score boundary.

end Union[InfBound, ScoreBoundary]

The end score boundary.

limit Optional[Limit]

The limit argument for a range query. Defaults to None. See Limit class for more information.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class RangeByScore:
    """
    Represents a range by score in a sorted set.

    The `start` and `end` arguments represent score boundaries.

    Attributes:
        start (Union[InfBound, ScoreBoundary]): The start score boundary.
        end (Union[InfBound, ScoreBoundary]): The end score boundary.
        limit (Optional[Limit]): The limit argument for a range query. Defaults to None. See `Limit`
            class for more information.
    """

    def __init__(
        self,
        start: Union[InfBound, ScoreBoundary],
        end: Union[InfBound, ScoreBoundary],
        limit: Optional[Limit] = None,
    ):
        self.start = (
            start.value["score_arg"] if isinstance(start, InfBound) else start.value
        )
        self.end = end.value["score_arg"] if isinstance(end, InfBound) else end.value
        self.limit = limit

RangeByLex

Represents a range by lexicographical order in a sorted set.

The start and end arguments represent lexicographical boundaries.

Attributes:

Name Type Description
start Union[InfBound, LexBoundary]

The start lexicographic boundary.

end Union[InfBound, LexBoundary]

The end lexicographic boundary.

limit Optional[Limit]

The limit argument for a range query. Defaults to None. See Limit class for more information.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
class RangeByLex:
    """
    Represents a range by lexicographical order in a sorted set.

    The `start` and `end` arguments represent lexicographical boundaries.

    Attributes:
        start (Union[InfBound, LexBoundary]): The start lexicographic boundary.
        end (Union[InfBound, LexBoundary]): The end lexicographic boundary.
        limit (Optional[Limit]): The limit argument for a range query. Defaults to None. See `Limit` class
            for more information.
    """

    def __init__(
        self,
        start: Union[InfBound, LexBoundary],
        end: Union[InfBound, LexBoundary],
        limit: Optional[Limit] = None,
    ):
        self.start = (
            start.value["lex_arg"] if isinstance(start, InfBound) else start.value
        )
        self.end = end.value["lex_arg"] if isinstance(end, InfBound) else end.value
        self.limit = limit

GeospatialData

Represents a geographic position defined by longitude and latitude.

The exact limits, as specified by EPSG:900913 / EPSG:3785 / OSGEO:41001 are the following:

- Valid longitudes are from -180 to 180 degrees.
- Valid latitudes are from -85.05112878 to 85.05112878 degrees.

Attributes:

Name Type Description
longitude float

The longitude coordinate.

latitude float

The latitude coordinate.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
class GeospatialData:
    """
    Represents a geographic position defined by longitude and latitude.

    The exact limits, as specified by EPSG:900913 / EPSG:3785 / OSGEO:41001 are the following:

        - Valid longitudes are from -180 to 180 degrees.
        - Valid latitudes are from -85.05112878 to 85.05112878 degrees.

    Attributes:
        longitude (float): The longitude coordinate.
        latitude (float): The latitude coordinate.
    """

    def __init__(self, longitude: float, latitude: float):
        self.longitude = longitude
        self.latitude = latitude

GeoUnit

Bases: Enum

Enumeration representing distance units options for the GEODIST command.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
class GeoUnit(Enum):
    """
    Enumeration representing distance units options for the `GEODIST` command.
    """

    METERS = "m"
    """
    Represents distance in meters.
    """
    KILOMETERS = "km"
    """
    Represents distance in kilometers.
    """
    MILES = "mi"
    """
    Represents distance in miles.
    """
    FEET = "ft"
    """
    Represents distance in feet.
    """

METERS = 'm' class-attribute instance-attribute

Represents distance in meters.

KILOMETERS = 'km' class-attribute instance-attribute

Represents distance in kilometers.

MILES = 'mi' class-attribute instance-attribute

Represents distance in miles.

FEET = 'ft' class-attribute instance-attribute

Represents distance in feet.

GeoSearchByRadius

Represents search criteria of searching within a certain radius from a specified point.

Attributes:

Name Type Description
radius float

Radius of the search area.

unit GeoUnit

Unit of the radius. See GeoUnit.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
class GeoSearchByRadius:
    """
    Represents search criteria of searching within a certain radius from a specified point.

    Attributes:
        radius (float): Radius of the search area.
        unit (GeoUnit): Unit of the radius. See `GeoUnit`.
    """

    def __init__(self, radius: float, unit: GeoUnit):
        """
        Initialize the search criteria.
        """
        self.radius = radius
        self.unit = unit

    def to_args(self) -> List[str]:
        """
        Convert the search criteria to the corresponding part of the command.

        Returns:
            List[str]: List representation of the search criteria.
        """
        return ["BYRADIUS", str(self.radius), self.unit.value]

to_args()

Convert the search criteria to the corresponding part of the command.

Returns:

Type Description
List[str]

List[str]: List representation of the search criteria.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
224
225
226
227
228
229
230
231
def to_args(self) -> List[str]:
    """
    Convert the search criteria to the corresponding part of the command.

    Returns:
        List[str]: List representation of the search criteria.
    """
    return ["BYRADIUS", str(self.radius), self.unit.value]

GeoSearchByBox

Represents search criteria of searching within a specified rectangular area.

Attributes:

Name Type Description
width float

Width of the bounding box.

height float

Height of the bounding box

unit GeoUnit

Unit of the radius. See GeoUnit.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
class GeoSearchByBox:
    """
    Represents search criteria of searching within a specified rectangular area.

    Attributes:
        width (float): Width of the bounding box.
        height (float): Height of the bounding box
        unit (GeoUnit): Unit of the radius. See `GeoUnit`.
    """

    def __init__(self, width: float, height: float, unit: GeoUnit):
        """
        Initialize the search criteria.
        """
        self.width = width
        self.height = height
        self.unit = unit

    def to_args(self) -> List[str]:
        """
        Convert the search criteria to the corresponding part of the command.

        Returns:
            List[str]: List representation of the search criteria.
        """
        return ["BYBOX", str(self.width), str(self.height), self.unit.value]

to_args()

Convert the search criteria to the corresponding part of the command.

Returns:

Type Description
List[str]

List[str]: List representation of the search criteria.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
252
253
254
255
256
257
258
259
def to_args(self) -> List[str]:
    """
    Convert the search criteria to the corresponding part of the command.

    Returns:
        List[str]: List representation of the search criteria.
    """
    return ["BYBOX", str(self.width), str(self.height), self.unit.value]

GeoSearchCount

Represents the count option for limiting the number of results in a GeoSearch.

Attributes:

Name Type Description
count int

The maximum number of results to return.

any_option bool

Whether to allow returning as enough matches are found. This means that the results returned may not be the ones closest to the specified point. Default to False.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
class GeoSearchCount:
    """
    Represents the count option for limiting the number of results in a GeoSearch.

    Attributes:
        count (int): The maximum number of results to return.
        any_option (bool): Whether to allow returning as enough matches are found.
            This means that the results returned may not be the ones closest to the specified point. Default to False.
    """

    def __init__(self, count: int, any_option: bool = False):
        """
        Initialize the count option.
        """
        self.count = count
        self.any_option = any_option

    def to_args(self) -> List[str]:
        """
        Convert the count option to the corresponding part of the command.

        Returns:
            List[str]: List representation of the count option.
        """
        if self.any_option:
            return ["COUNT", str(self.count), "ANY"]
        return ["COUNT", str(self.count)]

to_args()

Convert the count option to the corresponding part of the command.

Returns:

Type Description
List[str]

List[str]: List representation of the count option.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
279
280
281
282
283
284
285
286
287
288
def to_args(self) -> List[str]:
    """
    Convert the count option to the corresponding part of the command.

    Returns:
        List[str]: List representation of the count option.
    """
    if self.any_option:
        return ["COUNT", str(self.count), "ANY"]
    return ["COUNT", str(self.count)]

separate_keys(keys)

Returns separate lists of keys and weights in case of weighted keys.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/sorted_set.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def separate_keys(
    keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
) -> Tuple[List[TEncodable], List[TEncodable]]:
    """
    Returns separate lists of keys and weights in case of weighted keys.
    """
    if not keys:
        return [], []

    key_list: List[TEncodable] = []
    weight_list: List[TEncodable] = []

    if isinstance(keys[0], tuple):
        for item in keys:
            key = item[0]
            weight = item[1]
            key_list.append(cast(TEncodable, key))
            weight_list.append(cast(TEncodable, str(weight)))
    else:
        key_list.extend(cast(List[TEncodable], keys))

    return key_list, weight_list