Last active
January 3, 2016 13:29
-
-
Save pahud/8470112 to your computer and use it in GitHub Desktop.
This file contains 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 characters
//var http = require('http') | |
var express = require("express") | |
var ts = new Date().getTime() | |
var redis = require("redis") | |
var app = express() | |
var async = require('async') | |
client = redis.createClient('6379','xxx.xxx.xxx.xxx'); | |
var act1 = function(callback){ | |
var args1 = [ 'chat:rcv:1' , "("+ts, '0', 'withscores', 'limit', '0', '100' ]; | |
client.zrevrangebyscore(args1, function(err, resp){ | |
callback(null, resp) | |
}) | |
} | |
var act2 = function(input, callback){ | |
var k = '' | |
var v = '' | |
var i = 0 | |
var ptasks = [] | |
input.forEach( function(x) { | |
if (i % 2 == 0) { k = x } else | |
{ | |
v = x | |
ptasks.push( function(callback) | |
{ | |
client.hset('pahud:hash', k, v, function(err, res){ | |
callback(null, res) | |
}) // end hset | |
}) | |
} //end if | |
i++ | |
}) //end forEach | |
async.parallel(ptasks, function(err, results){ | |
callback(null, results) | |
}) | |
} // end function | |
app.get('/', function(req, res){ | |
req.connection.setTimeout(2*1000) | |
async.waterfall([act1, act2], function(err, result){ | |
res.json(result) | |
}) | |
}) | |
app.listen(8888); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment