2

I'm migrating from Heroku to Openshift since my app employs socket.io heavily. I seem to have hooked up redis correctly but just want to make sure.

When I enter this:

 rhc cartridge-status redis -a myapp

I get this:

Using smarterclayton-redis-2.6 (Redis) for 'redis'

RESULT:

Redis is running
  master (receives writes), mode sharded
  Connect to: xxhostnumberxx-myapp.rhcloud.com:xxportnumberxx password:xxsomepasswordxx

I then set ENV variables like so:

rhc set-env OPENSHIFT_REDIS_HOST=xxhostnumberxx-myapp.rhcloud.com -a myapp
rhc set-env OPENSHIFT_REDIS_PORT=com:xxportnumberxx -a myapp
rhc set-env REDIS_PASSWORD=password:xxsomepasswordxx -a myapp

And then in my app.js I have:

var redis;

// Openshift redis connection
if (process.env.OPENSHIFT_REDIS_HOST) {

    var redisHost = process.env.OPENSHIFT_REDIS_HOST;
    var redisPort = process.env.OPENSHIFT_REDIS_PORT;
    var redisPass = process.env.REDIS_PASSWORD;

    redis = require('redis').createClient(redisPort, redisHost);
    redis.auth(redisPass);
} 
// Localhost
else {
    redis = require('redis').createClient();
}

It seems to be working as my req.session is undefined error is gone (I'm using redis for session management).

I just want to make sure that I'm doing this right. Are the variables I set the correct ones and not going to change? Or is there a way to set them dynamically?

timo.rieber
  • 3,727
  • 3
  • 32
  • 47
OdieO
  • 6,836
  • 7
  • 56
  • 88

1 Answers1

1

Yea it looks good to me. You're setting the environment variables correctly with rhc set-env and since you're using the hostname and not the IP, it shouldn't change.

niharvey
  • 2,807
  • 2
  • 15
  • 24
  • The one doubt I had was that `xxhostnumberxx` was a 24 digit string which seems like it could change at random. So that's a permanent value? – OdieO Aug 22 '14 at 20:07
  • unless you change that app, the hostname should never change. – niharvey Aug 22 '14 at 20:26