Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import { queues } from "./queues";
  2. import redis from "redis";
  3.  
  4. queues.TEST_QUEUE.add({ key: "testJob" }, { delay: 5000 });
  5. export const client = redis.createClient(); // this creates a new client By default redis.createClient() will use 127.0.0.1 and port 6379.
  6. queues.TEST_QUEUE.process(async job => {
  7. client.on("connect", function() {
  8. console.log("Redis client connected");
  9. });
  10. client.on("error", function(err) {
  11. console.log("Something went wrong " + err);
  12. });
  13. job.progress(100);
  14. return await executeRedisCommand(client, job);
  15. });
  16. queues.TEST_QUEUE.on("completed", (job, result) => {
  17. console.log("result::", result);
  18. });
  19.  
  20. const executeRedisCommand = (client, job) =>
  21. new Promise((resolve, reject) => {
  22. client.INCR(`${job.data.key}`, (error, result) => {
  23. resolve(result);
  24. });
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement