Welcome to the Russel Client package! This library, crafted in JavaScript, enables seamless integration with the Russel service.
Get started by installing the package:
# npm
npm install Russel-js
Russel uses Authorization in order to set clusters. so you need to authorize yourself first.
After installing the russel application. russel by default creates a user with this credentials
admin // username
123456 // password
This is the default user with the highest priority that can add and remove profiles.
Now, before using the russel-js
API you need to call authorize
function when a new client is created.
// Example usage:
const russelClient = new RusselClient();
russelClient.authorize();
If you need to authorize as another user, there are two different ways to do so.
// Example usage:
const russelClient = new RusselClient('admin','123456'); // first arg is username and second is password
russelClient.authorize();
// Example usage:
const russelClient = new RusselClient(); // first arg is username and second is password
russelClient.setRusselConfig({
username:'admin',
password:123456
})
russelClient.authorize();
Russel-js offers two ways to handle responses from your client operations:
- Raw value
Retrieve the raw value directly:
const res = await russelClient.get({
cluster: 'foo',
key: 'bar',
});
console.log(res); // raw value
- Decoded Value
Alternatively, decode the value using the built-in function:
const res = await russelClient.get({
cluster: 'foo',
key: 'bar',
});
console.log(res.decodeData()); // decoded value
Russel-js
provides a straightforward API for CRUD operations. Here's a step-by-step guide on using its functionalities:
try {
const res = await russelClient.set({
cluster: 'foo',
key: 'bar',
value: 'fooBar',
});
console.log('Value set successfully');
} catch (error) {
console.error(error);
}
try {
const res = await russelClient.getCluster({
cluster: 'foo',
key: 'bar',
});
console.log(res.decodeData()); // 'fooBar'
} catch (error) {
console.error(error);
}
try {
const res = await russelClient.deleteCluster({
cluster: 'foo',
key: 'bar',
});
console.log('Value deleted');
} catch (error) {
console.error(error);
}
try {
const res = await russelClient.clearCluster('foo'); // cluster name
console.log('Cluster cleared');
} catch (error) {
console.error(error);
}
try {
const res = await russelClient.getKeysOfCluster('foo'); // cluster name
console.log(res); // ['bar']
} catch (error) {
console.error(error);
}
try {
const res = await russelClient.setCluster('foo'); // cluster name
console.log('Cluster created');
} catch (error) {
console.error(error);
}
try {
const res = await russelClient.checkConnection();
console.log('Connection successful');
} catch (error) {
console.error(error);
}
All responses are returned in the following format:
{
is_success: boolean, // operation status
data: this.data, // data itself
message: this.message // message
}
In case of errors, the response will include is_success set to false:
{
is_success: false, // operation status
message: this.message // error message
}
For more details, visit our GitHub organization. Happy coding! 🎉