Skip to content

Commit

Permalink
Add bulk feature
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Jan 7, 2024
1 parent 77c9039 commit de7a174
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 70 deletions.
9 changes: 7 additions & 2 deletions src/drivers/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export class Kivi {
constructor(config?: KiviConfig);
destroy(): void;

del(key: string): string | null;
del(key: string): boolean;
bulkDel(keys: string[]): boolean[];
fetchDel(key: string): string | null;
bulkFetchDel(keys: string[]): (string | null)[];
get(key: string): string | null;
set(key: string, value: string): string;
bulkGet(keys: string[]): (string | null)[];
set(key: string, value: string): boolean;
bulkSet(keys: string[], values: string[]): boolean[];
}
62 changes: 56 additions & 6 deletions src/drivers/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Kivi {
#InnerKivi;

/**
* Returns the value of the given key
* Initializes Kivi
* @param {{ forceUseRuntimeFFI: ?bool }} config
*/
constructor(config) {
Expand All @@ -56,35 +56,85 @@ export class Kivi {
throw new Error(`Failed to initialize a Kivi!`);
}
}
/**
* Releases the allocated memory and deinitializes Kivi.
* @returns {void}
*/
destroy() {
this.#InnerKivi.destroy();
}

/**
* Returns the value of the given key
* Returns the value of the given key.
* @param {string} key
* @returns {(string|null)}
*/
get(key) {
return this.#InnerKivi.get(key);
}
/**
* Sets a key to the given value
* Returns values of given keys.
* This function is noticeably faster when multiple data is given due to process in parallel.
* @param {string[]} keys
* @returns {(string|null)[]}
*/
bulkGet(keys) {
return this.#InnerKivi.bulkGet(keys);
}

/**
* Sets a key to the given value.
* @param {string} key
* @param {string} value
* @returns {void}
* @returns {boolean}
*/
set(key, value) {
if (!this.#InnerKivi.set(key, value)) {
throw new Error("Failed to insert!");
}
}
/**
* Removes a key with its value
* Sets values to given keys.
* This function is noticeably faster when multiple data is given due to process in parallel.
* @param {{key: string, value: string}[]} data
* @returns {boolean[]}
*/
bulkSet(data) {
return this.#InnerKivi.bulkSet(data);
}

/**
* Removes a key with its value.
* @param {string} key
* @returns {void}
*/
del(/** @type {string} */ key) {
del(key) {
return this.#InnerKivi.del(key);
}
/**
* Removes a key with its value and returns the value.
* @param {string} key
* @returns {string}
*/
fetchDel(key) {
return this.#InnerKivi.fetchDel(key);
}
/**
* Removes keys with their values and returns the values.
* This function is noticeably faster when multiple data is given due to process in parallel.
* @param {string[]} keys
* @returns {string[]}
*/
bulkFetchDel(keys) {
return this.#InnerKivi.bulkFetchDel(keys);
}
/**
* Removes keys with their values.
* This function is noticeably faster when multiple data is given due to process in parallel.
* @param {string[]} keys
* @returns {void}
*/
bulkDel(keys) {
return this.#InnerKivi.bulkDel(keys);
}
}
17 changes: 17 additions & 0 deletions src/drivers/js/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,27 @@ export class NodeKivi {
get(key) {
return addon.kivi_get(this.#buf, key);
}
bulkGet(keys) {
return addon.kivi_bulk_get(this.#buf, keys);
}

set(key, value) {
return addon.kivi_set(this.#buf, key, value);
}
bulkSet(data) {
return addon.kivi_bulk_set(this.#buf, data);
}

del(key) {
return addon.kivi_del(this.#buf, key);
}
fetchDel(key) {
return addon.kivi_fetch_del(this.#buf, key);
}
bulkFetchDel(keys) {
return addon.kivi_bulk_fetch_del(this.#buf, keys);
}
bulkDel(keys) {
return addon.kivi_bulk_del(this.#buf, keys);
}
}
Loading

0 comments on commit de7a174

Please sign in to comment.