0.0.2 • Published 9 months ago

@ceil-dev/redis-portal v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Redis Portal Library

Library for using Portals with Redis ether


Table of Contents

  1. Overview
  2. Installation
  3. Example
  4. License

Overview

Connect multiple node processes via Redis with Portals


Installation

npm install @ceil-dev/redis-portal

Example

import { createClient } from '@node-redis/client';
import { createRedisPortal, microEnv } from '@ceil-dev/redis-portal';

const run = async () => {
  // Assuming you have a redis server running on port 6379
  const port = 6379;

  const pubClient = createClient({
    url: 'redis://localhost:' + port, // Update with your Redis URL
  });
  pubClient.on('connect', () => {
    console.log('Connected to Redis (pub) on port', port);
  });
  pubClient.on('error', (err) => {
    console.error('Redis Client Error:', err);
  });
  pubClient.connect();

  const subClient = createClient({
    url: 'redis://localhost:' + port, // Update with your Redis URL
  });
  subClient.on('connect', () => {
    console.log('Connected to Redis (sub) on port', port);
  });
  subClient.on('error', (err) => {
    console.error('Redis Client Error:', err);
  });
  subClient.connect();

  const portal = createRedisPortal({
    pubClient,
    subClient,
    env: microEnv({ hello: 'world' }, { id: 'envA' }),
  });

  portal('open');

  // Now you can enter this portal "envA" from another local process
};

run().catch(console.error);

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.0.2

9 months ago

0.0.1

9 months ago