The socket.io-valkey-emitter package lets you communicate with a group of Socket.IO servers from another Node.js process — a worker, a cron job, an API service — anything that is not a Socket.IO server itself. It publishes events to Valkey, which the socket.io-valkey-adapter running on your Socket.IO servers picks up and delivers to the connected clients.
It is a Valkey-native port of @socket.io/redis-emitter — same API and behavior, backed by Valkey instead of Redis. It works with any ioredis-compatible Valkey client, such as iovalkey.
The diagram above shows the full flow. In short:
- Emitter (this package) — runs in any Node.js process (a worker, cron job, or API) and pushes events to clients by publishing to Valkey.
- Adapter (
socket.io-valkey-adapter, on your Socket.IO servers) — subscribes to Valkey, makes multiple servers act as one, and delivers the events to the connected clients.
Both must point at the same Valkey.
npm install socket.io-valkey-emitter iovalkeyconst { Emitter } = require("socket.io-valkey-emitter");
const Valkey = require("iovalkey");
const valkeyClient = new Valkey({ host: "localhost", port: 6379 });
const emitter = new Emitter(valkeyClient);
// broadcast to all connected clients
emitter.emit("time", new Date());
// to a room
emitter.to("room1").emit("hello", "world");
// to a namespace
emitter.of("/admin").emit("event", "payload");Your Socket.IO servers must use
socket.io-valkey-adapterpointed at the same Valkey for the emitted events to reach clients.
The emitter mirrors the Socket.IO broadcast API:
emitter.emit(event, ...args)— broadcast to allemitter.to(room)/emitter.in(room)— target a roomemitter.except(room)— exclude a roomemitter.of(namespace)— switch namespaceemitter.volatile/emitter.compress(bool)— flagsemitter.socketsJoin(rooms)/emitter.socketsLeave(rooms)— remote room managementemitter.disconnectSockets(close)— remotely disconnectemitter.serverSideEmit(event, ...args)— send to the servers (no acknowledgements)
MIT — a fork of @socket.io/redis-emitter.
