@ynode/redis
v1.0.3
Published
A better redis Fastify plugin.
Downloads
7
Readme
@ynode/redis
Copyright (c) 2025 Michael Welter [email protected]
A better Redis Fastify plugin that uses the official Redis library
Why?
A lightweight Fastify plugin that exposes a single node‑redis client (redis package) on your Fastify instance and handles connection lifecycle (connect → ready → reconnect → close) for you.
- ✅ Uses the official
redisclient (not ioredis) - ✅ Clean Fastify integration with proper startup/shutdown hooks
- ✅ Simple API:
fastify.rediseverywhere in your app
If you are looking for the ioredis‑based plugin, see
@fastify/redis.
Installation
Install the package and its required peer dependency, redis.
npm install @ynode/redis redis
Basic Usage
import redis from "@ynode/redis";
if (fastify.argv.redis) {
// connect to redis
await fastify.register(redis, { url: fastify.argv.redis });
}Usage
Register the plugin with your Fastify instance. Any options you provide are passed directly to the underlying node-redis createClient method.
import Fastify from "fastify";
import fastifyRedis from "@ynode/redis";
const fastify = Fastify({
logger: true
});
// Register the plugin with options
fastify.register(fastifyRedis, {
url: "redis://localhost:6379"
});
// Access the redis client from the fastify instance
fastify.get("/", async (request, reply) => {
const value = await fastify.redis.get("mykey");
return { key: "mykey", value: value };
});
const start = async () => {
try {
await fastify.listen({ port: 3000 });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();Options
This plugin passes all options directly to the createClient function from the official redis library.
For a full list of available options, please see the official node-redis documentation.
Release
To release a new version, use the included Makefile.
make release VERSION=1.2.3This command will:
- Check that
npmandpackage.jsonexist. - Run
npm versionto updatepackage.jsonand create a git tag. - Publish the package to npm.
- Push the commit and tags to the git remote.
License
This project is licensed under the MIT Lisence.
