Introduction

In case you missed the other days:
Day 1 Deep Dive
Day 2 Deep Dive with MongoDB
Day 3 Deep Dive with MongoDB
Day 4 Deep Dive with MongoDB
Day 5 Deep Dive with MongoDB
Day 6 Deep Dive with Mongoose
Day 7 Deep Dive with Clustering
Day 8 Deep Dive with PM2
Day 9 Deep Dive with Restify

After playing around with MongoDB I wanted to try out redis not only for it's performance comparison to MongoDB, but also for practical experience for use at work and in other projects. So tonight I will get it up and running on Windows, make connections in node.js and do some perf testing.

Prerequisites

You will need to install Redis. If you're on Windows, you can download the Windows port or if you're on Linux.

redis

To get started we need to install the npm package for redis:

npm install redis -g

Once installed, getting the redis client connecting to the server was pretty painless especially after using MongoDB previously. For the sake of this testing app I simply replaced the MongoDB dbFactory.js file like so:

var redis = require("redis"); var settings = require('./config'); var client = redis.createClient(settings.REDIS_DATABASE_POST, settings.REDIS_DATABASE_HOSTNAME); client.on("error", function (err) { console.log("Error " + err); }); module.exports = client;

Since redis uses a port/hostname split value I added two additional config options and removed the older database connection property:

module.exports = { REDIS_DATABASE_HOSTNAME: 'localhost', REDIS_DATABASE_POST: 6379, HTTP_SERVER_PORT: 1338 };

In the actual route for the test it only required a few adjustments:

var Router = require('restify-router').Router; var router = new Router(); var RedisClient = require('./dbFactory'); function respond(request, response, next) { var argId = request.params.id; RedisClient.set(argId.toString(), 2); return response.json({ message: true }); } router.get('/api/Test', respond); module.exports = router;

Performance

Interested in the performance differences I was not surprised at a direct comparison being so dramatic. I should note these were done on my Razer Blade laptop not my desktop.


When I add more functionality to provide full CRUD operations it will be interesting to really do an in-depth test comparing SQL Server, MongoDB and Redis.

Next up...

Tomorrow night I am planning on diving into Amazon Web Services (AWS) to get a good comparison to Rackspace and Azure. In particular for node.js development as I imagine node dev is more commonly done on AWS.

All of the code thus far is committed on GitHub.
TAGS
none on this post