Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { queues } from "./queues";
- import redis from "redis";
- queues.TEST_QUEUE.add({ key: "testJob" }, { delay: 5000 });
- export const client = redis.createClient(); // this creates a new client By default redis.createClient() will use 127.0.0.1 and port 6379.
- queues.TEST_QUEUE.process(async job => {
- client.on("connect", function() {
- console.log("Redis client connected");
- });
- client.on("error", function(err) {
- console.log("Something went wrong " + err);
- });
- job.progress(100);
- return await executeRedisCommand(client, job);
- });
- queues.TEST_QUEUE.on("completed", (job, result) => {
- console.log("result::", result);
- });
- const executeRedisCommand = (client, job) =>
- new Promise((resolve, reject) => {
- client.INCR(`${job.data.key}`, (error, result) => {
- resolve(result);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement