Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
/ comet-redis Public archive

Component to easily communicate between each parts of the comet application.

License

Notifications You must be signed in to change notification settings

starry-comet/comet-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

comet-redis

NSP Status Codacy Badge

Roles

This project has to main to give a lightweight redis client that allow to you to easily subscribe and publish between components.

Usage

To use comet-redis, see the example below:

import {injectable, inject} from 'comet-ioc'
import {RedisPublisher, RedisSubscriber} from 'comet-redis'

@injectable()
export class MainClass {
  public constructor(
    @inject(RedisPublisher) $publisher: RedisPublisher
    @inject(RedisSubscriber) $subscriber: RedisSubscriber
  ) {
    $subscriber.subscribe<string>('channel', {
      next(message: string): void {
        console.log(message)
      },

      error(error: Error): void {},
      complete(): void {}
    })

    setTimeout(() => {
      $publisher.publish('channel', 'hi !')
    }, 1000)
  }
}
import {bootstrap, interfaces} from 'comet-ioc'
import {RedisModule, RedisToken, RedisFactory, Redis} from 'comet-redis'

import {MainClass} from './a/file'

bootstrap(MainClass, {
  imports: [RedisModule],
  providers: [{
    provide: RedisToken,
    useFactory(context: interfaces.Context): Redis {
      return RedisFactory('redis://127.0.0.1:6379')
    }
  }]
})

result:

hi !