@mistercoookie/redis-pub-sub
v1.0.5
Published
``` npm i @mistercoookie/redis-pub-sub ```
Downloads
2
Readme
Installation
npm i @mistercoookie/redis-pub-sub
Initialization
import { RedisService } from '@mistercoookie/redis-pub-sub'
RedisService.initService("<yout-redis url>")
Subscription
import { RedisService, RedisPublication } from '@mistercoookie/redis-pub-sub'
RedisService.subscribeChannel(
'Your Channel',
(redisPublication: RedisPublication) => {
// Your logic
}
)
Publication
import { RedisService } from '@mistercoookie/redis-pub-sub'
RedisService.publish('Your Channel', 'Some Data')
Publication with needed response
Publisher
import { RedisService } from '@mistercoookie/redis-pub-sub'
async function yourFunction(
const answer = await RedisService.publishWithAnswer(
'Your Channel',
'Some Data'
)
)
Subscriber
import { RedisService, RedisPublication } from '@mistercoookie/redis-pub-sub'
onYourChannel(redisPublication: RedisPublication) {
// Your Logic
if (redisPublication.expectingAnswer) {
RedisService.publish(
daredisPublicationta.answerChannel,
answerData
)
}
}
RedisService.subscribeChannel(
'Your Channel',
(redisPublication: RedisPublication) => {
this.onYourChannel(redisPublication)
}
)
Author
ELISABETH Nathanaël