Skip to content

Instantly share code, notes, and snippets.

@pahud
Last active January 3, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pahud/8470112 to your computer and use it in GitHub Desktop.
Save pahud/8470112 to your computer and use it in GitHub Desktop.
//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