-
Notifications
You must be signed in to change notification settings - Fork 0
Add redis pub/sub to project #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import {connect, RedisConnectOptions} from "https://deno.land/x/redis/mod.ts"; | ||
| import {Task} from "../tasks/task.ts"; | ||
|
|
||
| let redis: any; | ||
| let pub :any; | ||
| let sub:any | ||
|
|
||
| export const initRedis = async (options:RedisConnectOptions) => { | ||
| redis = await connect(options); | ||
| pub = await connect(options); | ||
| sub = await connect(options); | ||
| } | ||
|
|
||
| export const subscribe = async (channel: string) => { | ||
| const subscribe = await sub.subscribe(channel); | ||
| await (async function () { | ||
| for await (const {channel, message} of subscribe.receive()) { | ||
| console.log({channel, message:message}) | ||
| } | ||
| })(); | ||
| } | ||
|
|
||
| const publish = async (channel: string, data:any) => { | ||
| console.log("publish ", data) | ||
| return pub.publish(channel, JSON.stringify(data)); | ||
| } | ||
|
|
||
| export const addTaskToRedis = async (task:Task)=>{ | ||
| return publish(task.name, task) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, this module should not know anything about tasks. It should be concerned with saving and receiving data from Redis. We need another module/package to handle connecting to tasks. WDYT?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I should separate the concerns |
||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this do the job? Since the parent function is already defined as async.