@greencoast/djs-extended-data-provider-redis - v1.0.0

ci-build-status issues bundle-size node-version version djs-extended-version downloads-week downloads-total

Discord.js - Extended / Redis Data Provider

djs-extended-data-provider-redis is an implementation of a DataProvider for discord.js-extended made with a Redis backend.

Keep in mind that Redis was originally meant to be a cache, data is deleted by default across service restarts. You can achieve persistence by properly configuring your Redis instance.

Usage

You can visit the documentation site to see what this utility offers.

Installation

This package is designed to work for discord.js and @greencoast/discord.js-extended, this does not install any of these packages, you are expected to have these in your project.

You can install this package with:

npm install discord.js @greencoast/discord.js-extended @greencoast/djs-extended-data-provider-redis

Adding the Data Provider to your Client

Assuming you have created your own ExtendedClient, you can attach this data provider into your client as such:

const { RedisDataProvider } = require('@greencoast/djs-extended-data-provider-redis');

const client = new ExtendedClient();

client.once('ready', async () => {
await client.setDataProvider(new RedisDataProvider(client, {
url: 'redis://localhost:6379'
}));
});

And that's it! You can then access the data provider across your code through client.dataProvider.

Using Data Provider

You can use the following methods anywhere:

await client.dataProvider.get(guild, 'key'); // Get a value for 'key' in guild.
await client.dataProvider.set(guild, 'key', 'value'); // Set 'value' for 'key' in guild.
await client.dataProvider.delete(guild, 'key'); // Delete a key-value pair for 'key' in guild.
await client.dataProvider.clear(guild); // Clear all data in a guild.

await client.dataProvider.getGlobal('key'); // Get a value for 'key' in the global scope.
await client.dataProvider.setGlobal('key', 'value'); // Set 'value' for 'key' in the global scope.
await client.dataProvider.deleteGlobal('key'); // Delete a key-value pair for 'key' in the global scope.
await client.dataProvider.clearGlobal(); // Clear all data in the global scope.

If you're using TypeScript, you should pass a generic type to the get and delete methods as such:

await client.dataProvider.get<string>(guild, 'key'); // Promise<string | undefined>
await client.dataProvider.get<string>(guild, 'key', 'default'); // Promise<string>

await client.dataProvider.delete<string>(guild, 'key'); // Promise<string | undefined>

Testing

You can run the unit tests for this package by:

  1. Cloning the repo:
git clone https://github.com/greencoast-studios/djs-extended-data-provider-redis
  1. Installing the dependencies.
npm install
  1. Running the tests.
npm test

Authors

This utility library was made by Greencoast Studios.

Generated using TypeDoc