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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
unless you change that app, the hostname should never change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.