title: Redis client connects to the redis remote server but can't read or write on it
body: <p>In DegitalOcean, i have to manage two servers 'Nodeserver' and a redis server 'Redisserver' by making the connection possible from a node/express application on the former for using the latter's database.</p>
  
  <p>For the purpose of local tests, i've also installed another redis server 'LocalRedisOnNodeServer' locally on 'Nodeserver'.</p>
  
  <p>I have configured the 'Redisserver' to accept external connections as in <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04" rel="nofollow">https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04</a> and when trying to connect from the 'LocalRedisOnNodeServer's redis-cli i was able to access the remote 'Redis_server' database and reading and writting operations were also possible through it.</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>and this is the config.js :</p>
  
  <pre><code>var config = {
  port: 3000,
  secret: 'secret',
  
  redisConf: {
  host: 'xxx.xxx.xxx.xxx.', // The redis's server ip 
  port: '6379',
  pass: 'theredispass'
  }
  };    
  module.exports = config;
  </code></pre>
  
  <p>I've tested the app connection to the local redis server 'LocalRedisOnNodeServer' 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 'Redisserver' 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.</p>
  
  <p>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.</p>
  
  <p>No errors were mentioned in redis_6379.log</p>
  
  <p>Best regards</p>