Redis key value store and Node.js

My application uses node.js and socket.io for communication between server and client. For communication between server and local hardware/programs I need a way to pass events and variables from node.js to python. The solution I am using is to store the values in Redis and access them from both node.js and python. First Redis needs to be installed; on Ubuntu simply run

sudo apt-get install redis-server
This will also start the redis server. Then cd to the nodejs directory and run
npm install hiredis redis
This will install the redis client as well as the non-blocking hiredis client.

From the node.js program Redis is used similar to other database clients.

var redis = require('redis')
  ,redisClient = redis.createClient();
Then values can be stored and retrieved with simple set and get commands.
redisClient.set("keyName", "Value", callbackFunction);
redisClient.get("keyName", function (err, reply) {
        console.log(reply.toString()); // prints "Value" to the console
    });

On the python side I install redis-py

sudo pip install redis
Then in my python code I simply import redis and run the normal get and set commands.
import redis;
r = redis.StrictRedis(host='localhost', port=6379, db=0);
y = r.get('keyName');
print y;

Read More