A lightweight JavaScript client for interacting with a Duke distributed key-value cluster.
npm install duke-clientconst duke = new Duke();duke.seturl(
"duke://localhost:8000",
"duke://localhost:8001",
"duke://localhost:8002",
);Multiple URLs can be provided.
Before performing any operations, call connect().
const connected = await duke.connect();
if (!connected) {
console.log("No healthy Duke nodes found.");
}The client checks the health of all configured nodes and stores only healthy ones for future requests.
Store a key-value pair.
await duke.PUT("name", "Duke");Returns:
true;Retrieve a value by key.
const value = await duke.GET("name");
console.log(value);Output:
DukeIf the key does not exist:
Error: Key not found.import Duke from "duke-client";
const duke = new Duke();
duke.seturl(
"duke://localhost:8000",
"duke://localhost:8001",
"duke://localhost:8002",
);
const connected = await duke.connect();
if (!connected) {
throw new Error("No Duke nodes available.");
}
await duke.PUT("username", "baltej");
const value = await duke.GET("username");
console.log(value); const result = await db.batch_PUT(keys, vals, 1000); const result = await db.batch_GET(keys, 1000);