npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

redis-threading

v1.0.5

Published

Bibliothèque de multithreading avec Redis pour Node.js/TypeScript

Readme

Redis Threading

Une bibliothèque robuste de multithreading pour Node.js/TypeScript utilisant Redis comme support pour la communication, la synchronisation et la mise en file d'attente des tâches.

Caractéristiques

  • Pool de Workers - Gestion efficace de worker threads pour les calculs parallèles
  • File d'Attente Distribuée - Distribution et synchronisation des tâches via Redis
  • Communication Inter-Processus - Communication Pub/Sub entre les nœuds
  • État Partagé - Partage de données entre les processus avec notifications de changement
  • Verrous Distribués - Synchronisation de sections critiques entre plusieurs instances
  • Monitoring - Surveillance de la santé et des performances du système
  • Hautement Évolutif - Conception pour une scalabilité horizontale et verticale

Installation

npm install redis-threading
yarn add redis-threading
bun install redis-threading
pnpm install redis-threading

Prérequis

  • Node.js >= 16.0.0
  • Redis Server >= 5.0.0

Utilisation Rapide

import RedisThreading from 'redis-threading';
import * as path from 'path';

async function main() {
  // Créer une instance avec la configuration
  const rt = new RedisThreading({
    redis: {
      host: 'localhost',
      port: 6379,
      password: '',
      db: 0,
    },
    namespace: 'myapp',
  });

  // Initialiser la bibliothèque
  await rt.initialize();

  // Initialiser le worker pool
  await rt.initializeWorkerPool(path.resolve(__dirname, './worker.js'));

  // Enregistrer des handlers de tâches
  rt.registerTaskHandler('math:add', async (data) => {
    return { result: data.a + data.b };
  });

  // Démarrer le consommateur de files d'attente
  rt.startQueueConsumer(2, ['default']);

  // Exécuter une tâche localement
  const result = await rt.executeTask('math:add', { a: 5, b: 3 });
  console.log('Résultat:', result.result);

  // Soumettre une tâche à la file d'attente Redis
  rt.enqueueTask('math:multiply', { a: 4, b: 7 }).then((result) =>
    console.log('Résultat:', result.result)
  );

  // Partager des données
  await rt.setState('counter', 1);

  // S'abonner aux changements
  rt.onStateChange('counter', (newValue) => {
    console.log('Nouveau compteur:', newValue);
  });

  // Fermeture propre
  process.on('SIGINT', async () => {
    await rt.shutdown();
    process.exit(0);
  });
}

main().catch(console.error);

Documentation Complète

Pour une documentation complète incluant tous les concepts avancés, consultez le Wiki.

Design Patterns Utilisés

Cette bibliothèque implémente plusieurs design patterns pour une architecture propre et maintenable :

  • Singleton - Pour les gestionnaires globaux (WorkerPool, QueueManager, etc.)
  • Factory - Pour la création d'objets complexes (RedisClientFactory)
  • Repository - Pour l'abstraction des accès aux données (TaskQueue)
  • Observer - Pour les notifications d'événements (MessageBroker, SharedState)
  • Command - Pour l'encapsulation des actions (TaskExecutor)
  • Strategy - Pour les différentes stratégies de distribution des tâches
  • Façade - Pour une interface simplifiée (RedisThreading)

Licence

MIT