Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Duke JS Client

A lightweight JavaScript client for interacting with a Duke distributed key-value cluster.

Installation

npm install duke-client

Usage

Create a Client

const duke = new Duke();

Add Duke Nodes

duke.seturl(
  "duke://localhost:8000",
  "duke://localhost:8001",
  "duke://localhost:8002",
);

Multiple URLs can be provided.

Connect

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.


PUT

Store a key-value pair.

await duke.PUT("name", "Duke");

Returns:

true;

GET

Retrieve a value by key.

const value = await duke.GET("name");

console.log(value);

Output:

Duke

If the key does not exist:

Error: Key not found.

Health Checking

The client verifies node health using db.checkHealth()

Example

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);

Batched PUTs/GETs

fn: batch_PUT(keyArr:Array, valueArr:Array, batch_size:Number)

 const result = await db.batch_PUT(keys, vals, 1000);

fn: batch_GET(keyArr:Array, batch_size:Number)

 const result = await db.batch_GET(keys, 1000);

For key not found, it will print an error; "KeyNotFound".

About

JS client (sdk) for Duke distributed db.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages