Route request to all primary nodes.
Route request to all nodes.
The Routes type allows you to specify how a command should be routed in a Valkey cluster.
Commands can be routed to a single node or broadcast to multiple nodes depending on the routing strategy.
Routing Options:
SingleNodeRoute):
SlotIdTypes: Route based on a specific slot ID.SlotKeyTypes: Route based on the slot of a specific key.RouteByAddress: Route to a specific node by its address and port.// Route command to a random node
const routeRandom: Routes = "randomNode";
// Route command to all primary nodes
const routeAllPrimaries: Routes = "allPrimaries";
// Route command to all nodes
const routeAllNodes: Routes = "allNodes";
// Route command to a node by slot key
const routeByKey: Routes = {
type: "primarySlotKey",
key: "myKey",
};
// Route command to a specific node by address
const routeByAddress: Routes = {
type: "routeByAddress",
host: "192.168.1.10",
port: 6379,
};
// Use the routing configuration when executing a command
const result = await client.ping({ route: routeByAddress });
Defines the routing configuration for a command in a Valkey cluster.