项目作者: starry-comet

项目描述 :
Component to easily communicate between each parts of the comet application.
高级语言: TypeScript
项目地址: git://github.com/starry-comet/comet-redis.git
创建时间: 2017-03-12T17:47:56Z
项目社区:https://github.com/starry-comet/comet-redis

开源协议:MIT License

下载


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:

  1. import {injectable, inject} from 'comet-ioc'
  2. import {RedisPublisher, RedisSubscriber} from 'comet-redis'
  3. @injectable()
  4. export class MainClass {
  5. public constructor(
  6. @inject(RedisPublisher) $publisher: RedisPublisher
  7. @inject(RedisSubscriber) $subscriber: RedisSubscriber
  8. ) {
  9. $subscriber.subscribe<string>('channel', {
  10. next(message: string): void {
  11. console.log(message)
  12. },
  13. error(error: Error): void {},
  14. complete(): void {}
  15. })
  16. setTimeout(() => {
  17. $publisher.publish('channel', 'hi !')
  18. }, 1000)
  19. }
  20. }
  1. import {bootstrap, interfaces} from 'comet-ioc'
  2. import {RedisModule, RedisToken, RedisFactory, Redis} from 'comet-redis'
  3. import {MainClass} from './a/file'
  4. bootstrap(MainClass, {
  5. imports: [RedisModule],
  6. providers: [{
  7. provide: RedisToken,
  8. useFactory(context: interfaces.Context): Redis {
  9. return RedisFactory('redis://127.0.0.1:6379')
  10. }
  11. }]
  12. })

result:

  1. hi !