MyUnisoft Redis package.
- Node.js version 18 or higher.
- Docker (for running tests).
Tip
If you ever want to setup a local instance of Redis,
you can follow the Redis documentation for Mac,
or, you can use Memurai for Windows.
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @myunisoft/redis
# or
$ yarn add @myunisoft/redis
This class is used to instantiate and close connection to Redis. You need to re-use this instance in every other classes.
type ConnectionOptions = Partial<RedisOptions> & {
port?: number;
host?: string;
attempt?: number;
disconnectionTimeout?: number;
};
import assert from "assert";
import {
Connection
} from "@myunisoft/redis";
const connection = new Connection();
try {
(await connection.initialize()).unwrap();
}
finally {
await connection.close();
}
type AssertConnectionErr = "Failed at initializing the Redis connection";
This function either return void, or an error;
type GetConnectionPerfResponse = {
isAlive: boolean;
perf: number;
};
This function is used to check Redis connection state.
const instancePerf = await getConnectionPerf();
if (!instancePerf.isAlive) {
console.log(instancePerf.isAlive);
console.log(instancePerf.perf);
}
console.log(instancePerf.isAlive);
console.log(instancePerf.perf);
type AssertDisconnectionErr = AssertDisconnectionErrorMessage;
type CloseErr = AssertDisconnectionErrorMessage | "Redis connection already closed";
This function is used to close the Redis connection related to the instance.
The package also exports many classes listed below.
Thanks goes to these wonderful people (emoji key):
Nicolas Hallaert 💻 |
PierreDemailly 👀 |
Thomas.G 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!