Last active
January 24, 2019 12:40
-
-
Save dangvanduc90/4c716cce70aa716517dd83bcc96c4b74 to your computer and use it in GitHub Desktop.
Revisions
-
dangvanduc90 revised this gist
Jan 24, 2019 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,9 @@ import bodyParser from 'body-parser'; let port = process.env.PORT || 3001; let client = redis.createClient({ host: DB_HOST_REDIS, // các bạn thay thông số redis database ở đây port: DB_PORT_REDIS, // các bạn thay thông số redis database ở đây db: DB_NAME_REDIS // các bạn thay thông số redis database ở đây }); app.use(bodyParser.json()); @@ -29,13 +29,15 @@ client.on("connect", function () { doWork() }); // function này chạy liên tục function doWork() { client.keys('email_ticket_redis:*', function(err, result){ // với email_ticket_redis là key bên PHP insert vào redis if (err) return sendLog(createLog(err)) if (result.length > 0) { // luôn luôn phải có try catch để nếu có lỗi thì cũng ko stop vòng lặp của chúng ta try { } catch (err) { sendLog(createLog(err)) } -
dangvanduc90 created this gist
Jan 24, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ let app = require('express')(); let http = require('http').Server(app); import redis from 'redis'; import bodyParser from 'body-parser'; let port = process.env.PORT || 3001; let client = redis.createClient({ host: DB_HOST_REDIS, port: DB_PORT_REDIS, db: DB_NAME_REDIS }); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); http.listen(port, function(){ console.log('Listening on http://localhost:' + port); }); client.on("error", function (err) { console.log("Error " + err); }); client.on("connect", function () { doWork() }); function doWork() { client.keys('email_ticket_redis:*', function(err, result){ if (err) return sendLog(createLog(err)) if (result.length > 0) { try { } catch (err) { sendLog(createLog(err)) } setImmediate(() => { doWork(); }); } else { setTimeout(() => { doWork(); },1000) } }) }