Skip to content

glide_shared.commands.core_options

PubSubMsg dataclass

Describes the incoming pubsub message

Attributes:

Name Type Description
message TEncodable

Incoming message.

channel TEncodable

Name of an channel that triggered the message.

pattern Optional[TEncodable]

Pattern that triggered the message.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@dataclass
class PubSubMsg:
    """
    Describes the incoming pubsub message

    Attributes:
        message (TEncodable): Incoming message.
        channel (TEncodable): Name of an channel that triggered the message.
        pattern (Optional[TEncodable]): Pattern that triggered the message.
    """

    message: TEncodable
    channel: TEncodable
    pattern: Optional[TEncodable]

MonitorMsg dataclass

Represents a single line received from the MONITOR command.

Attributes:

Name Type Description
timestamp float

Unix timestamp of the command.

db int

Database index on which the command was executed.

client_addr str

Address of the client that issued the command.

command str

The command name.

args List[str]

The command arguments.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@dataclass
class MonitorMsg:
    """
    Represents a single line received from the MONITOR command.

    Attributes:
        timestamp (float): Unix timestamp of the command.
        db (int): Database index on which the command was executed.
        client_addr (str): Address of the client that issued the command.
        command (str): The command name.
        args (List[str]): The command arguments.
    """

    timestamp: float
    db: int
    client_addr: str
    command: str
    args: List[str]

ConditionalChange

Bases: Enum

A condition to the SET, ZADD, GEOADD and HSETEX commands.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class ConditionalChange(Enum):
    """
    A condition to the `SET`, `ZADD`, `GEOADD` and `HSETEX` commands.
    """

    ONLY_IF_EXISTS = "XX"
    """ Only update key / elements that already exist. Equivalent to `XX` in the Valkey API. """

    ONLY_IF_DOES_NOT_EXIST = "NX"
    """ Only set key / add elements that does not already exist. Equivalent to `NX` in the Valkey API. """

    def _to_args(self) -> List[TEncodable]:
        """
        Returns the condition as a list of command arguments.
        """
        return [self.value]

ONLY_IF_EXISTS = 'XX' class-attribute instance-attribute

Only update key / elements that already exist. Equivalent to XX in the Valkey API.

ONLY_IF_DOES_NOT_EXIST = 'NX' class-attribute instance-attribute

Only set key / add elements that does not already exist. Equivalent to NX in the Valkey API.

HashFieldConditionalChange

Bases: Enum

Field conditional change options for HSETEX command.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
66
67
68
69
70
71
72
73
74
75
class HashFieldConditionalChange(Enum):
    """
    Field conditional change options for HSETEX command.
    """

    ONLY_IF_ALL_EXIST = "FXX"
    """ Only set fields if all of them already exist. Equivalent to `FXX` in the Valkey API. """

    ONLY_IF_NONE_EXIST = "FNX"
    """ Only set fields if none of them already exist. Equivalent to `FNX` in the Valkey API. """

ONLY_IF_ALL_EXIST = 'FXX' class-attribute instance-attribute

Only set fields if all of them already exist. Equivalent to FXX in the Valkey API.

ONLY_IF_NONE_EXIST = 'FNX' class-attribute instance-attribute

Only set fields if none of them already exist. Equivalent to FNX in the Valkey API.

ValueComparison dataclass

Bases: ABC

A condition that compares the current value of a key to a comparison value.

Attributes:

Name Type Description
comparison_value TEncodable

The value to compare to the current value of a key.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@dataclass
class ValueComparison(ABC):
    """
    A condition that compares the current value of a key to a comparison value.

    Attributes:
        comparison_value (TEncodable): The value to compare to the current value of a key.
    """

    comparison_value: TEncodable

    @abstractmethod
    def _to_args(self) -> List[TEncodable]:
        """
        Returns the condition as a list of command arguments.
        """
        pass

OnlyIfEqual dataclass

Bases: ValueComparison

A condition that is met if the key exists and its current value is equal to the comparison value. Used by the SET command. Equivalent to the IFEQ comparison-value in the Valkey API.

Not supported when compression is enabled. See Valkey GLIDE - Data Compression <https://glide.valkey.io/concepts/client-features/compression/#incompatible-commands>_.

Since: Valkey 8.1.0.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
class OnlyIfEqual(ValueComparison):
    """
    A condition that is met if the key exists and its current value is equal to the comparison value.
    Used by the `SET` command. Equivalent to the `IFEQ comparison-value` in the Valkey API.

    Not supported when compression is enabled. See
    `Valkey GLIDE - Data Compression <https://glide.valkey.io/concepts/client-features/compression/#incompatible-commands>`_.

    Since: Valkey 8.1.0.
    """

    def _to_args(self) -> List[TEncodable]:
        return ["IFEQ", self.comparison_value]

OnlyIfNotEqual dataclass

Bases: ValueComparison

A condition that is met if the key does not exist or its current value is not equal to the comparison value. Used by the SET command. Equivalent to the IFNE comparison-value in the Valkey API.

Not supported when compression is enabled. See Valkey GLIDE - Data Compression <https://glide.valkey.io/concepts/client-features/compression/#incompatible-commands>_.

Since: Valkey 9.2.0.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
112
113
114
115
116
117
118
119
120
121
122
123
124
class OnlyIfNotEqual(ValueComparison):
    """
    A condition that is met if the key does not exist or its current value is not equal to the comparison value.
    Used by the `SET` command. Equivalent to the `IFNE comparison-value` in the Valkey API.

    Not supported when compression is enabled. See
    `Valkey GLIDE - Data Compression <https://glide.valkey.io/concepts/client-features/compression/#incompatible-commands>`_.

    Since: Valkey 9.2.0.
    """

    def _to_args(self) -> List[TEncodable]:
        return ["IFNE", self.comparison_value]

ExpiryType

Bases: Enum

SET option: The type of the expiry.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
class ExpiryType(Enum):
    """
    SET option: The type of the expiry.
    """

    SEC = 0, Union[int, timedelta]
    """
    Set the specified expire time, in seconds. Equivalent to `EX` in the Valkey API.
    """

    MILLSEC = 1, Union[int, timedelta]
    """
    Set the specified expire time, in milliseconds. Equivalent to `PX` in the Valkey API.
    """

    UNIX_SEC = 2, Union[int, datetime]
    """
    Set the specified Unix time at which the key will expire, in seconds. Equivalent to `EXAT` in the Valkey API.
    """

    UNIX_MILLSEC = 3, Union[int, datetime]
    """
    Set the specified Unix time at which the key will expire, in milliseconds. Equivalent to `PXAT` in the Valkey API.
    """

    KEEP_TTL = 4, Type[None]
    """
    Retain the time to live associated with the key. Equivalent to `KEEPTTL` in the Valkey API.
    """

SEC = (0, Union[int, timedelta]) class-attribute instance-attribute

Set the specified expire time, in seconds. Equivalent to EX in the Valkey API.

MILLSEC = (1, Union[int, timedelta]) class-attribute instance-attribute

Set the specified expire time, in milliseconds. Equivalent to PX in the Valkey API.

UNIX_SEC = (2, Union[int, datetime]) class-attribute instance-attribute

Set the specified Unix time at which the key will expire, in seconds. Equivalent to EXAT in the Valkey API.

UNIX_MILLSEC = (3, Union[int, datetime]) class-attribute instance-attribute

Set the specified Unix time at which the key will expire, in milliseconds. Equivalent to PXAT in the Valkey API.

KEEP_TTL = (4, Type[None]) class-attribute instance-attribute

Retain the time to live associated with the key. Equivalent to KEEPTTL in the Valkey API.

ExpiryTypeGetEx

Bases: Enum

GetEx option: The type of the expiry.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class ExpiryTypeGetEx(Enum):
    """
    GetEx option: The type of the expiry.
    """

    SEC = 0, Union[int, timedelta]
    """ Set the specified expire time, in seconds. Equivalent to `EX` in the Valkey API. """

    MILLSEC = 1, Union[int, timedelta]
    """ Set the specified expire time, in milliseconds. Equivalent to `PX` in the Valkey API. """

    UNIX_SEC = 2, Union[int, datetime]
    """ Set the specified Unix time at which the key will expire, in seconds. Equivalent to `EXAT` in the Valkey API. """

    UNIX_MILLSEC = 3, Union[int, datetime]
    """ Set the specified Unix time at which the key will expire, in milliseconds. Equivalent to `PXAT` in the Valkey API. """

    PERSIST = 4, Type[None]
    """ Remove the time to live associated with the key. Equivalent to `PERSIST` in the Valkey API. """

SEC = (0, Union[int, timedelta]) class-attribute instance-attribute

Set the specified expire time, in seconds. Equivalent to EX in the Valkey API.

MILLSEC = (1, Union[int, timedelta]) class-attribute instance-attribute

Set the specified expire time, in milliseconds. Equivalent to PX in the Valkey API.

UNIX_SEC = (2, Union[int, datetime]) class-attribute instance-attribute

Set the specified Unix time at which the key will expire, in seconds. Equivalent to EXAT in the Valkey API.

UNIX_MILLSEC = (3, Union[int, datetime]) class-attribute instance-attribute

Set the specified Unix time at which the key will expire, in milliseconds. Equivalent to PXAT in the Valkey API.

PERSIST = (4, Type[None]) class-attribute instance-attribute

Remove the time to live associated with the key. Equivalent to PERSIST in the Valkey API.

InfoSection

Bases: Enum

INFO option: a specific section of information:

When no parameter is provided, the default option is assumed.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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
235
236
237
238
239
240
241
242
class InfoSection(Enum):
    """
    INFO option: a specific section of information:

    When no parameter is provided, the default option is assumed.
    """

    ALL = "all"
    """ Return all sections (excluding module generated ones) """

    CLIENTS = "clients"
    """ Client connections section """

    CLUSTER = "cluster"
    """ Valkey Cluster section """

    CLUSTER_INFO = "cluster_info"
    """
    Valkey Cluster information.

    Since: Valkey 9.1.0.
    """

    COMMAND_STATS = "commandstats"
    """ Valkey command statistics """

    CPU = "cpu"
    """ CPU consumption statistics """

    DEFAULT = "default"
    """ Return only the default set of sections """

    ERROR_STATS = "errorstats"
    """ Valkey error statistics """

    EVERYTHING = "everything"
    """ Includes all and modules """

    KEYSPACE = "keyspace"
    """ Database related statistics """

    LATENCY_STATS = "latencystats"
    """ Valkey command latency percentile distribution statistics """

    MEMORY = "memory"
    """ Memory consumption related information """

    MODULES = "modules"
    """ Modules section """

    PERSISTENCE = "persistence"
    """ RDB and AOF related information """

    REPLICATION = "replication"
    """ Master/replica replication information """

    SENTINEL = "sentinel"
    """ Valkey Sentinel section (only applicable to Sentinel instances) """

    SERVER = "server"
    """ General information about the server """

    STATS = "stats"
    """ General statistics """

ALL = 'all' class-attribute instance-attribute

Return all sections (excluding module generated ones)

CLIENTS = 'clients' class-attribute instance-attribute

Client connections section

CLUSTER = 'cluster' class-attribute instance-attribute

Valkey Cluster section

CLUSTER_INFO = 'cluster_info' class-attribute instance-attribute

Valkey Cluster information.

Since: Valkey 9.1.0.

COMMAND_STATS = 'commandstats' class-attribute instance-attribute

Valkey command statistics

CPU = 'cpu' class-attribute instance-attribute

CPU consumption statistics

DEFAULT = 'default' class-attribute instance-attribute

Return only the default set of sections

ERROR_STATS = 'errorstats' class-attribute instance-attribute

Valkey error statistics

EVERYTHING = 'everything' class-attribute instance-attribute

Includes all and modules

KEYSPACE = 'keyspace' class-attribute instance-attribute

Database related statistics

LATENCY_STATS = 'latencystats' class-attribute instance-attribute

Valkey command latency percentile distribution statistics

MEMORY = 'memory' class-attribute instance-attribute

Memory consumption related information

MODULES = 'modules' class-attribute instance-attribute

Modules section

PERSISTENCE = 'persistence' class-attribute instance-attribute

RDB and AOF related information

REPLICATION = 'replication' class-attribute instance-attribute

Master/replica replication information

SENTINEL = 'sentinel' class-attribute instance-attribute

Valkey Sentinel section (only applicable to Sentinel instances)

SERVER = 'server' class-attribute instance-attribute

General information about the server

STATS = 'stats' class-attribute instance-attribute

General statistics

ExpireOptions

Bases: Enum

EXPIRE option: options for setting key expiry.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
class ExpireOptions(Enum):
    """
    EXPIRE option: options for setting key expiry.
    """

    HasNoExpiry = "NX"
    """ Set expiry only when the key has no expiry (Equivalent to "NX" in Valkey). """

    HasExistingExpiry = "XX"
    """ Set expiry only when the key has an existing expiry (Equivalent to "XX" in Valkey). """

    NewExpiryGreaterThanCurrent = "GT"
    """
    Set expiry only when the new expiry is greater than the current one (Equivalent to "GT" in Valkey).
    """

    NewExpiryLessThanCurrent = "LT"
    """
    Set expiry only when the new expiry is less than the current one (Equivalent to "LT" in Valkey).
    """

HasNoExpiry = 'NX' class-attribute instance-attribute

Set expiry only when the key has no expiry (Equivalent to "NX" in Valkey).

HasExistingExpiry = 'XX' class-attribute instance-attribute

Set expiry only when the key has an existing expiry (Equivalent to "XX" in Valkey).

NewExpiryGreaterThanCurrent = 'GT' class-attribute instance-attribute

Set expiry only when the new expiry is greater than the current one (Equivalent to "GT" in Valkey).

NewExpiryLessThanCurrent = 'LT' class-attribute instance-attribute

Set expiry only when the new expiry is less than the current one (Equivalent to "LT" in Valkey).

UpdateOptions

Bases: Enum

Options for updating elements of a sorted set key.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
267
268
269
270
271
272
273
274
275
276
class UpdateOptions(Enum):
    """
    Options for updating elements of a sorted set key.
    """

    LESS_THAN = "LT"
    """ Only update existing elements if the new score is less than the current score. """

    GREATER_THAN = "GT"
    """ Only update existing elements if the new score is greater than the current score. """

LESS_THAN = 'LT' class-attribute instance-attribute

Only update existing elements if the new score is less than the current score.

GREATER_THAN = 'GT' class-attribute instance-attribute

Only update existing elements if the new score is greater than the current score.

ExpirySet

SET option: Represents the expiry type and value to be executed with "SET" command.

Attributes:

Name Type Description
cmd_arg str

The expiry type.

value str

The value for the expiry type.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
class ExpirySet:
    """
    SET option: Represents the expiry type and value to be executed with "SET" command.

    Attributes:
        cmd_arg (str): The expiry type.
        value (str): The value for the expiry type.
    """

    def __init__(
        self,
        expiry_type: ExpiryType,
        value: Optional[Union[int, datetime, timedelta]],
    ) -> None:
        self.set_expiry_type_and_value(expiry_type, value)

    def __eq__(self, other: "object") -> bool:
        if not isinstance(other, ExpirySet):
            return NotImplemented
        return self.expiry_type == other.expiry_type and self.value == other.value

    def set_expiry_type_and_value(
        self, expiry_type: ExpiryType, value: Optional[Union[int, datetime, timedelta]]
    ):
        """
        Args:
            expiry_type (ExpiryType): The expiry type.
            value (Optional[Union[int, datetime, timedelta]]): The value of the expiration type. The type of expiration
                determines the type of expiration value:

                    - SEC: Union[int, timedelta]
                    - MILLSEC: Union[int, timedelta]
                    - UNIX_SEC: Union[int, datetime]
                    - UNIX_MILLSEC: Union[int, datetime]
                    - KEEP_TTL: Type[None]
        """
        if not isinstance(value, get_args(expiry_type.value[1])):
            raise ValueError(
                f"The value of {expiry_type} should be of type {expiry_type.value[1]}"
            )
        self.expiry_type = expiry_type
        if self.expiry_type == ExpiryType.SEC:
            self.cmd_arg = "EX"
            if isinstance(value, timedelta):
                value = int(value.total_seconds())
        elif self.expiry_type == ExpiryType.MILLSEC:
            self.cmd_arg = "PX"
            if isinstance(value, timedelta):
                value = int(value.total_seconds() * 1000)
        elif self.expiry_type == ExpiryType.UNIX_SEC:
            self.cmd_arg = "EXAT"
            if isinstance(value, datetime):
                value = int(value.timestamp())
        elif self.expiry_type == ExpiryType.UNIX_MILLSEC:
            self.cmd_arg = "PXAT"
            if isinstance(value, datetime):
                value = int(value.timestamp() * 1000)
        elif self.expiry_type == ExpiryType.KEEP_TTL:
            self.cmd_arg = "KEEPTTL"
        self.value = str(value) if value is not None else None

    def get_cmd_args(self) -> List[str]:
        return [self.cmd_arg] if self.value is None else [self.cmd_arg, self.value]

set_expiry_type_and_value(expiry_type, value)

Parameters:

Name Type Description Default
expiry_type ExpiryType

The expiry type.

required
value Optional[Union[int, datetime, timedelta]]

The value of the expiration type. The type of expiration determines the type of expiration value:

- SEC: Union[int, timedelta]
- MILLSEC: Union[int, timedelta]
- UNIX_SEC: Union[int, datetime]
- UNIX_MILLSEC: Union[int, datetime]
- KEEP_TTL: Type[None]
required
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
def set_expiry_type_and_value(
    self, expiry_type: ExpiryType, value: Optional[Union[int, datetime, timedelta]]
):
    """
    Args:
        expiry_type (ExpiryType): The expiry type.
        value (Optional[Union[int, datetime, timedelta]]): The value of the expiration type. The type of expiration
            determines the type of expiration value:

                - SEC: Union[int, timedelta]
                - MILLSEC: Union[int, timedelta]
                - UNIX_SEC: Union[int, datetime]
                - UNIX_MILLSEC: Union[int, datetime]
                - KEEP_TTL: Type[None]
    """
    if not isinstance(value, get_args(expiry_type.value[1])):
        raise ValueError(
            f"The value of {expiry_type} should be of type {expiry_type.value[1]}"
        )
    self.expiry_type = expiry_type
    if self.expiry_type == ExpiryType.SEC:
        self.cmd_arg = "EX"
        if isinstance(value, timedelta):
            value = int(value.total_seconds())
    elif self.expiry_type == ExpiryType.MILLSEC:
        self.cmd_arg = "PX"
        if isinstance(value, timedelta):
            value = int(value.total_seconds() * 1000)
    elif self.expiry_type == ExpiryType.UNIX_SEC:
        self.cmd_arg = "EXAT"
        if isinstance(value, datetime):
            value = int(value.timestamp())
    elif self.expiry_type == ExpiryType.UNIX_MILLSEC:
        self.cmd_arg = "PXAT"
        if isinstance(value, datetime):
            value = int(value.timestamp() * 1000)
    elif self.expiry_type == ExpiryType.KEEP_TTL:
        self.cmd_arg = "KEEPTTL"
    self.value = str(value) if value is not None else None

ExpiryGetEx

GetEx option: Represents the expiry type and value to be executed with "GetEx" command.

Attributes:

Name Type Description
cmd_arg str

The expiry type.

value str

The value for the expiry type.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
class ExpiryGetEx:
    """
    GetEx option: Represents the expiry type and value to be executed with "GetEx" command.

    Attributes:
        cmd_arg (str): The expiry type.
        value (str): The value for the expiry type.
    """

    def __init__(
        self,
        expiry_type: ExpiryTypeGetEx,
        value: Optional[Union[int, datetime, timedelta]],
    ) -> None:
        self.set_expiry_type_and_value(expiry_type, value)

    def set_expiry_type_and_value(
        self,
        expiry_type: ExpiryTypeGetEx,
        value: Optional[Union[int, datetime, timedelta]],
    ):
        """
        Args:
            expiry_type (ExpiryType): The expiry type.
            value (Optional[Union[int, datetime, timedelta]]): The value of the expiration type. The type of expiration
                determines the type of expiration value:

                    - SEC: Union[int, timedelta]
                    - MILLSEC: Union[int, timedelta]
                    - UNIX_SEC: Union[int, datetime]
                    - UNIX_MILLSEC: Union[int, datetime]
                    - PERSIST: Type[None]
        """
        if not isinstance(value, get_args(expiry_type.value[1])):
            raise ValueError(
                f"The value of {expiry_type} should be of type {expiry_type.value[1]}"
            )
        self.expiry_type = expiry_type
        if self.expiry_type == ExpiryTypeGetEx.SEC:
            self.cmd_arg = "EX"
            if isinstance(value, timedelta):
                value = int(value.total_seconds())
        elif self.expiry_type == ExpiryTypeGetEx.MILLSEC:
            self.cmd_arg = "PX"
            if isinstance(value, timedelta):
                value = int(value.total_seconds() * 1000)
        elif self.expiry_type == ExpiryTypeGetEx.UNIX_SEC:
            self.cmd_arg = "EXAT"
            if isinstance(value, datetime):
                value = int(value.timestamp())
        elif self.expiry_type == ExpiryTypeGetEx.UNIX_MILLSEC:
            self.cmd_arg = "PXAT"
            if isinstance(value, datetime):
                value = int(value.timestamp() * 1000)
        elif self.expiry_type == ExpiryTypeGetEx.PERSIST:
            self.cmd_arg = "PERSIST"
        self.value = str(value) if value is not None else None

    def get_cmd_args(self) -> List[str]:
        return [self.cmd_arg] if self.value is None else [self.cmd_arg, self.value]

set_expiry_type_and_value(expiry_type, value)

Parameters:

Name Type Description Default
expiry_type ExpiryType

The expiry type.

required
value Optional[Union[int, datetime, timedelta]]

The value of the expiration type. The type of expiration determines the type of expiration value:

- SEC: Union[int, timedelta]
- MILLSEC: Union[int, timedelta]
- UNIX_SEC: Union[int, datetime]
- UNIX_MILLSEC: Union[int, datetime]
- PERSIST: Type[None]
required
Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def set_expiry_type_and_value(
    self,
    expiry_type: ExpiryTypeGetEx,
    value: Optional[Union[int, datetime, timedelta]],
):
    """
    Args:
        expiry_type (ExpiryType): The expiry type.
        value (Optional[Union[int, datetime, timedelta]]): The value of the expiration type. The type of expiration
            determines the type of expiration value:

                - SEC: Union[int, timedelta]
                - MILLSEC: Union[int, timedelta]
                - UNIX_SEC: Union[int, datetime]
                - UNIX_MILLSEC: Union[int, datetime]
                - PERSIST: Type[None]
    """
    if not isinstance(value, get_args(expiry_type.value[1])):
        raise ValueError(
            f"The value of {expiry_type} should be of type {expiry_type.value[1]}"
        )
    self.expiry_type = expiry_type
    if self.expiry_type == ExpiryTypeGetEx.SEC:
        self.cmd_arg = "EX"
        if isinstance(value, timedelta):
            value = int(value.total_seconds())
    elif self.expiry_type == ExpiryTypeGetEx.MILLSEC:
        self.cmd_arg = "PX"
        if isinstance(value, timedelta):
            value = int(value.total_seconds() * 1000)
    elif self.expiry_type == ExpiryTypeGetEx.UNIX_SEC:
        self.cmd_arg = "EXAT"
        if isinstance(value, datetime):
            value = int(value.timestamp())
    elif self.expiry_type == ExpiryTypeGetEx.UNIX_MILLSEC:
        self.cmd_arg = "PXAT"
        if isinstance(value, datetime):
            value = int(value.timestamp() * 1000)
    elif self.expiry_type == ExpiryTypeGetEx.PERSIST:
        self.cmd_arg = "PERSIST"
    self.value = str(value) if value is not None else None

FlushMode

Bases: Enum

Defines flushing mode for:

FLUSHALL command and FUNCTION FLUSH command.

See FLUSHALL and FUNCTION-FLUSH for details

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
411
412
413
414
415
416
417
418
419
420
421
422
class FlushMode(Enum):
    """
    Defines flushing mode for:

    `FLUSHALL` command and `FUNCTION FLUSH` command.

    See [FLUSHALL](https://valkey.io/commands/flushall/) and [FUNCTION-FLUSH](https://valkey.io/commands/function-flush/)
    for details
    """

    ASYNC = "ASYNC"
    SYNC = "SYNC"

FunctionRestorePolicy

Bases: Enum

Options for the FUNCTION RESTORE command.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
class FunctionRestorePolicy(Enum):
    """
    Options for the FUNCTION RESTORE command.
    """

    APPEND = "APPEND"
    """ Appends the restored libraries to the existing libraries and aborts on collision. This is the default policy. """

    FLUSH = "FLUSH"
    """ Deletes all existing libraries before restoring the payload. """

    REPLACE = "REPLACE"
    """
    Appends the restored libraries to the existing libraries, replacing any existing ones in case
    of name collisions. Note that this policy doesn't prevent function name collisions, only libraries.
    """

APPEND = 'APPEND' class-attribute instance-attribute

Appends the restored libraries to the existing libraries and aborts on collision. This is the default policy.

FLUSH = 'FLUSH' class-attribute instance-attribute

Deletes all existing libraries before restoring the payload.

REPLACE = 'REPLACE' class-attribute instance-attribute

Appends the restored libraries to the existing libraries, replacing any existing ones in case of name collisions. Note that this policy doesn't prevent function name collisions, only libraries.

ClientPauseMode

Bases: Enum

Mode option for the CLIENT PAUSE command.

See CLIENT PAUSE for details.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
443
444
445
446
447
448
449
450
451
452
453
454
class ClientPauseMode(Enum):
    """
    Mode option for the `CLIENT PAUSE` command.

    See [CLIENT PAUSE](https://valkey.io/commands/client-pause/) for details.
    """

    ALL = "ALL"
    """ Pause all client commands. """

    WRITE = "WRITE"
    """ Pause client write commands. """

ALL = 'ALL' class-attribute instance-attribute

Pause all client commands.

WRITE = 'WRITE' class-attribute instance-attribute

Pause client write commands.

MigrateOptions dataclass

Optional arguments for the migrate command. See valkey.io for details.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/commands/core_options.py
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
@dataclass
class MigrateOptions:
    """
    Optional arguments for the `migrate` command.
    See [valkey.io](https://valkey.io/commands/migrate/) for details.
    """

    copy: bool = False
    replace: bool = False
    password: Optional[str] = None
    username: Optional[str] = None

    def to_args(self) -> List[TEncodable]:
        if self.username is not None and self.password is None:
            raise ValueError("MigrateOptions: 'username' requires 'password' to be set")
        args: List[TEncodable] = []
        if self.copy:
            args.append("COPY")
        if self.replace:
            args.append("REPLACE")
        if self.username is not None and self.password is not None:
            args.extend(["AUTH2", self.username, self.password])
        elif self.password is not None:
            args.extend(["AUTH", self.password])
        return args