The redis module can be installed using npm.
npm install redis
To use redis in your Node applications, you have to include the module, which can be done using the below command.
var redis = require('redis');
To create a client in redis, you have to use the below command.
var client = redis.createClient();
This above createClient() method takes three optional parameters : port,host,options. By default, the host is set to 127.0.0.1 and the port is set to 6379.
The third parameter is an object that supports the following options :
return_buffers : By default false, if its true all replies are set as Node buffer rather than strings.
no_ready_check : By default false, if its true "ready check" sent to server to check if its is ready for more commands.
detect_buffers : By default fasle, if its true all replies are sent as buffer objects.
socket_nodelay : By default true, it tells whether to call setNoDelay on TCP stream.
Its good to leave all the options as default, but if you want to play with these values to see whats the difference, just go on and change values.
Now if you have created a connection with the client, you can send several commands until you explicitly call client.quit method. You can also call client.end method, but its good to call client.end method if your application is stuck or you want to start over.
The redis.print method prints either the error or the reply to the console and returns.
Please Like and Share the Blog, if you find it interesting and helpful.