Authenticating

We can set the authentication for Redis with the redis.conf file, found in the directory we installed Redis in.

To set a password in redis.conf, we simply uncomment the require pass section, supplying the desired password (for the sake of a concrete example, let's choose the password "ourpassword").

Then, we make sure that our Redis server points to the configuration file.

If we are running it from the src directory, we would then start our Redis server with the following command:

$ ./redis-server ../redis.conf 

As an alternative, if we want to quickly set a temporary password, we can use the following:

$ echo "requirepass ourpassword" | ./redis-server - 

We can also set a password from within Node with the CONFIG SET Redis command:

client.config('SET', 'requirepass', 'ourpassword') 

To authenticate a Redis server within Node, we use the redis module's client.auth method before any other calls:

   client.auth('ourpassword') 

The password has to be sent before any other commands.

The redis module seamlessly handles re-authentication; we don't need to call client.auth again at failure points, this is taken care of internally.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset