nodejs redis with kue module init
2014-01-15 14:26
375 查看
/** * Kue Monitor */ var kue = require('kue') var redis = require('redis'); var jf = require("jsonfile") var path = require("path") /* * get user home dir */ function getUserHome() { return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; } /** * set redis credentials . * Priority : * 1 VCAP_SERVICES * 2 user.home/.redis-server.json * 3 config/redis-server.json * 4 default as local:6379 , no password */ function getCredentials(callback){ if (process.env.VCAP_SERVICES) { var env = JSON.parse(process.env.VCAP_SERVICES); return env['redis-2.6'][0].credentials; } else { jf.readFile(path.join(getUserHome(),".redis-server.json"), function(err,data){ console.log("read local redis json file") if(err){ jf.readFile("./config/redis-server.json", function(err,data){ if(err){ var credentials credentials.host="127.0.0.1" credentials.port=6379 credentials.password='' callback(credentials) }else{ callback(data["redis-2.6"][0]["credentials"]) } }) }else{ callback(data["redis-2.6"][0]["credentials"]) } }) }; } /** * create que client */ function init(){ getCredentials(function(credentials){ console.log("redis server ...") console.log(credentials) kue.redis.createClient = function() { console.log("host:"+ credentials.host) console.log("port:"+ credentials.port) console.log("password:"+ credentials.password) var client = redis.createClient(credentials.port, credentials.host); if (credentials.password != '') { client.auth(credentials.password); } return client; } mountUI() }) } function mountUI(){ kue.app.set('title', 'Redis Que Monitor'); console.log("Monitor Service @ 3030 is started.") kue.app.listen(3030) } init()
相关文章推荐
- [Node.js]32. Level 7: Working with Lists -- Redis
- Building Faster APIs with NodeJs and Redis
- Using Redis with Node.js
- Javascript Module pattern template. Shows a class with a constructor and public/private methods/properties. Also shows compatibility with CommonJS(eg Node.JS) and AMD (eg requireJS) as well as in a br
- Node.js Request Module…sending json in body for api request with put
- 在Node.js应用中使用Redis的方法简介
- Experimenting with Node.js - Jeff Kreeftmeijer
- Node.js : Using Promises with mongoosejs
- [Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands
- NodeJS+Redis实现分布式Session方案
- Node.js中的exports与module.exports的区分
- Node.js中exports与module.exports的区别
- Learning Server-Side JavaScript with Node.js
- node.js与redis
- Asynchronous Code Design with Node.js
- Node.js中exports与module.exports的区别
- [Node.js] Build microservices in Node.js with micro
- [转]Getting Start With Node.JS Tools For Visual Studio
- Node.js Setup:This may indicate a problem with this package. The error code is 2503.
- node.js中exports与module.exports区别