Verokv
is a lightweight Node.js client SDK for interacting with a key-value store server over a TCP connection. It allows you to easily connect to the server and perform set
and get
operations on key-value pairs.
Make sure you have Verokv server setup. Read more here
To use Verokv in your project, add it to your project dependencies.
npm install verokv-ts
# OR
pnpm add verokv-ts
# OR
yarn install verokv-ts
import Verokv from 'verokv';
Initialize a Verokv instance by providing the server's hostname and port number.
const verokv = new Verokv('localhost', 6379);
Use the set method to store a value with a specified key.
verokv.set('name', 'Alice')
.then(() => {
console.log('Key-value pair set successfully');
})
.catch((err) => {
console.error('Error setting key-value:', err);
});
Use the get method to retrieve the value of a specific key.
verokv.get('name')
.then((value) => {
console.log('Retrieved value:', value);
})
.catch((err) => {
console.error('Error retrieving key-value:', err);
});
Verokv handles connection and request errors automatically. If an error occurs during a set or get operation, the returned promise will be rejected with an error message.
Here's a complete example of using Verokv to connect to a key-value store server, set a key-value pair, and retrieve it.
import Verokv from 'verokv';
const verokv = new Verokv('localhost', 6379);
verokv.set('username', 'johndoe')
.then(() => {
return verokv.get('username');
})
.then((value) => {
console.log('Retrieved username:', value);
})
.catch((err) => {
console.error('Operation error:', err);
});