Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

I’ve to manage two servers ‘Node_server’ and a redis server ‘Redis_server’ by making the connection possible from a node/express application on the former for using the latter’s database.
For the purpose of local tests, i’ve also installed another redis server ‘LocalRedis_OnNodeServer’ locally on ‘Node_server’.
I have configured the ‘Redis_server’ to accept external connections as in https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04 and when trying to connect from the 'LocalRedis_OnNodeServer’s redis-cli i was able to access the remote ‘Redis_server’ database and reading and writting operations were also possible through it.
I still didn’t configure any security’s mesures for ‘Redis_server’ (as to edit iptables…) and i’ve only set a password (requirepass in the redis.conf) and i still don’t know if a more secured authentification can be made with SSH on this server (or to configure my application code for it too).
The following is the app.js file which contains the express’s session and the RedisStore (receiving a redis client as args) passed to the session.
/*************************************** app.js ******************************************************/ var express = require(‘express’); var app = express(); var routes = require(‘./routes’); var errorHandlers = require(‘./middleware/errorhandlers’); var log = require(‘./middleware/log’); var partials = require(‘express-partials’); var cookieParser = require(‘cookie-parser’); var session = require(‘express-session’); var RedisStore = require(‘connect-redis’)(session); var bodyParser = require(‘body-parser’); var redis = require(‘redis’); var config = require(‘./config’);
app.set(‘view engine’, ‘ejs’); app.set(‘view options’, {defaultLayout: ‘layout’});
app.use(partials()); app.use(log.logger); app.use(express.static(__dirname + ‘/static’)); app.use(cookieParser(config.secret));
console.log(config.redisConf);
var redisClient = redis.createClient(config.redisConf);
redisClient.on(‘connect’, function() { console.log(‘connected to redis!!’); });
redisClient.set(‘framework’, ‘AngularJS’, function(err, reply) { console.log('the framwork var was SET to AngularJS : the following is the server answer : '); console.log(reply); });
app.use(session({
secret: config.secret,
resave: false,
saveUninitialized: true,
store: new RedisStore({client: redisClient})
}));
// right after the session app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false}));
app.get(‘/’, routes.index); app.get(‘/login’, routes.login); app.post(‘/login’, routes.loginProcess); app.get(‘/chat’, routes.chat); app.get(‘/account/login’, routes.login);
app.get(‘/error’, function(req, res, next){ next(new Error(‘A contrived error’)); });
app.use(errorHandlers.error); app.use(errorHandlers.notFound);
app.listen(config.port); console.log("App server running on port " + config.port); /********************************************************************************************************/
and this is the config.js :
/*********************************** config.js ****************************************************/
var config = { port: 3000, secret: ‘secret’, redisConf: { host: ‘xxx.xxx.xxx.xxx.’, // The redis’s server ip port: ‘6379’, pass: ‘the_redis_pass’ } };
module.exports = config; /********************************************************************************************************/
I’ve tested the app connection to the local redis server ‘LocalRedis_OnNodeServer’ and and it was successful as well as reading and writing keys (for the set and get…). which is a proof that the app code is fine. But when i changed from the redis host (redisConf.host ) from the local 127.0.0.1 to the ‘Redis_server’ ip, only the connection occurs (the redisClient.on(‘connect’ callback logs that it’s ‘connected to redis!!’ but reading and writting functions(get and set) fail as their callbacks haven’t been triggered and the other problem was that the express’s session couldn’t be created and its value remains to undefined.
I wonder why the connection as well as reading and writting operations were all possible within the local redis server’s client on the 'Node_server’s shell (the redis-cli) to the remote server while the redisClient in application code failed.
Best regards.
Junaid Ali
c16a0681e4174db280c83e4625c16d
phosphide
be910cccb6cf4b3ebf23fdcffa5505
7785fb23466745bea08552220fe464
Rashmi Joshi
Zappcode Academy
Mads Jürgensen
bee575eae7d04977a721d68f4f4877
endtoendpaper
David Macias