Last active
August 29, 2015 14:00
-
-
Save goalsin/11164587 to your computer and use it in GitHub Desktop.
express + node_redis model
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
exports.exec = function(command,args){ | |
var util = require('util'); | |
var app = require('../app'); | |
var Q = require('q'); | |
var client = app.get('db'); | |
var deferred = Q.defer(); | |
client.send_command(command, args, function(error,result){ | |
if (error) { | |
deferred.reject(new Error(error)); | |
} else { | |
console.log('redis return result = '+util.inspect(result, false, null)); | |
deferred.resolve(result); | |
} | |
}); | |
return deferred.promise; | |
} | |
exports.exec_once = function(command,args,cb_succuss,cb_error){ | |
return this.exec(command,args).then(function(data){ | |
if(cb_succuss){ | |
cb_succuss(data); | |
} | |
}).fail(function (error) { | |
console.log('error = '+util.inspect(result, false, null)); | |
}).done(); | |
} | |
exports.get_unique_userid_with_exec_once = function(cb_s,cb_e){ | |
return this.exec_once('INCR',"global:nextUserId",cb_s,cb_e); | |
}; | |
exports.get_unique_userid_with_exec = function(res,cb_s,cb_e){ | |
return this.exec('INCR',"global:nextUserId").then(function(data){ | |
res.send('respond with a resource' + data); | |
}).fail(function (error) { | |
console.log('error = '+util.inspect(result, false, null)); | |
}).done(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment