Skip to content

glide_shared.routes

SlotType

Bases: Enum

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
15
16
17
18
19
20
21
22
23
24
25
26
27
class SlotType(Enum):
    PRIMARY = 1
    """
    Address a primary node.
    """

    REPLICA = 2
    """
    Address a replica node.

    `REPLICA` overrides the `read_from_replica` configuration. If it's used the request
    will be routed to a replica, even if the strategy is `ALWAYS_FROM_MASTER`.
    """

PRIMARY = 1 class-attribute instance-attribute

Address a primary node.

REPLICA = 2 class-attribute instance-attribute

Address a replica node.

REPLICA overrides the read_from_replica configuration. If it's used the request will be routed to a replica, even if the strategy is ALWAYS_FROM_MASTER.

AllNodes

Bases: Route

Route request to all nodes.

Warning

Don't use it with write commands, they could be routed to a replica (RO) node and fail.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
38
39
40
41
42
43
44
45
46
class AllNodes(Route):
    """
    Route request to all nodes.

    Warning:
        Don't use it with write commands, they could be routed to a replica (RO) node and fail.
    """

    pass

AllPrimaries

Bases: Route

Route request to all primary nodes.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
49
50
51
52
53
54
class AllPrimaries(Route):
    """
    Route request to all primary nodes.
    """

    pass

RandomNode

Bases: Route

Route request to a random node.

Warning

Don't use it with write commands, because they could be randomly routed to a replica (RO) node and fail.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
57
58
59
60
61
62
63
64
65
class RandomNode(Route):
    """
    Route request to a random node.

    Warning:
        Don't use it with write commands, because they could be randomly routed to a replica (RO) node and fail.
    """

    pass

SlotKeyRoute

Bases: Route

Routes a request to a node by its slot key

Attributes:

Name Type Description
slot_type SlotType

Defines type of the node being addressed.

slot_key str

The request will be sent to nodes managing this key.

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
68
69
70
71
72
73
74
75
76
77
78
79
class SlotKeyRoute(Route):
    """Routes a request to a node by its slot key

    Attributes:
        slot_type (SlotType): Defines type of the node being addressed.
        slot_key (str): The request will be sent to nodes managing this key.
    """

    def __init__(self, slot_type: SlotType, slot_key: str) -> None:
        super().__init__()
        self.slot_type = slot_type
        self.slot_key = slot_key

SlotIdRoute

Bases: Route

Routes a request to a node by its slot ID

Attributes:

Name Type Description
slot_type SlotType

Defines type of the node being addressed.

slot_id int

Slot number. There are 16384 slots in a Valkey cluster, and each shard manages a slot range. Unless the slot is known, it's better to route using SlotType.PRIMARY

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class SlotIdRoute(Route):
    """Routes a request to a node by its slot ID

    Attributes:
        slot_type (SlotType): Defines type of the node being addressed.
        slot_id (int): Slot number. There are 16384 slots in a Valkey cluster, and each shard
            manages a slot range. Unless the slot is known, it's better to route using
            `SlotType.PRIMARY`
    """

    def __init__(self, slot_type: SlotType, slot_id: int) -> None:
        super().__init__()
        self.slot_type = slot_type
        self.slot_id = slot_id

ByAddressRoute

Bases: Route

Routes a request to a node by its address

Attributes:

Name Type Description
host str

The endpoint of the node. If port is not provided, should be in the f"{address}:{port}" format, where address is the preferred endpoint as shown in the output of the CLUSTER SLOTS command.

port Optional[int]

The port to access on the node. If port is not provided, host is assumed to be in the format f"{address}:{port}".

Source code in doc-gen/valkey-glide/python/glide-shared/glide_shared/routes.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class ByAddressRoute(Route):
    """Routes a request to a node by its address

    Attributes:
        host (str): The endpoint of the node. If `port` is not provided, should be in the f"{address}:{port}" format,
            where `address` is the preferred endpoint as shown in the output of the `CLUSTER SLOTS` command.
        port (Optional[int]): The port to access on the node. If port is not provided, `host` is assumed to be in
            the format f"{address}:{port}".
    """

    def __init__(self, host: str, port: Optional[int] = None) -> None:
        super().__init__()
        if port is None:
            split = host.split(":")
            if len(split) < 2:
                raise RequestError(
                    "No port provided, expected host to be formatted as {hostname}:{port}`. Received "
                    + host
                )
            self.host = split[0]
            self.port = int(split[1])
        else:
            self.host = host
            self.port = port