Stanley Luo Stanley Luo - 10 months ago 52
Node.js Question

Do I need to specify a client for connect-redis?

I'm trying to use redis on a node express server to store user sessions, by using the connect-redis(on Github) library. And I find this block of settings works well:

var app = express();

secret: 'hahahahahahahahahaha',
cookie: { maxAge: 36000000 },
store: new redisStore(),

Notice I didn't pass any params to
new redisStore()
and it also works for now (in its documentation a
is passed), guess it's using localhost and default port by default.

But I'm worrying, if I put my server on AWS EC2 in the future which is a shared server, will that be a problem if I don't specify a client? Say, will redis conflicts with other servers also hosting on that EC2?

Answer Source

You are using a redis client here. You just relinquished the configuration of the client though. That will be a problem in the future, as (presumably) you will be deploying on AWS in a cluster. The redis client needs to be common across instances.

If you don't define the port number and other details of the client, you basically are undoing the purpose of having state management. Your redis clients will be limited to your own instance.

Go through for more info.

The idea is to have one (or a cluster) of redis instances that run independent of your AWS instances, so that state is shared across all of your instances. That is why you need to have complete control of your redis client