Route request to a random node.
Route request to the node that contains the slot with the given id.
Route request to the node that contains the slot that the given key matches.
The SingleNodeRoute type allows you to specify routing of a command to a single node in the cluster.
This can be based on various criteria such as a random node, a node responsible for a specific slot, or a node identified by its address.
Options:
SlotIdTypes: Route to the node responsible for a specific slot ID.SlotKeyTypes: Route to the node responsible for the slot of a specific key.RouteByAddress: Route to a specific node by its address and port.// Route to a random node
const routeRandomNode: SingleNodeRoute = "randomNode";
// Route based on slot ID
const routeBySlotId: SingleNodeRoute = {
type: "primarySlotId",
id: 12345,
};
// Route based on key
const routeByKey: SingleNodeRoute = {
type: "primarySlotKey",
key: "myKey",
};
// Route to a specific node by address
const routeByAddress: SingleNodeRoute = {
type: "routeByAddress",
host: "192.168.1.10",
port: 6379,
};
// Use the routing configuration when executing a command
const result = await client.get("myKey", { route: routeByKey });
Defines the routing configuration to a single node in the Valkey cluster.