I'm looking at this code snippet:
var addSnippet = function( req, res ) {
getPostParams( req, function( obj ) {
var r = redis.createClient();
r.stream.on( 'connect', function() {
r.incr( 'nextid' , function( err, id ) {
r.set( 'snippet:'+id, JSON.stringify( obj ), function() {
var msg = 'The snippet has been saved at <a href="/'+id+'">'+req.headers.host+'/'+id+'</a>';
res.respond( msg );
} );
} );
} );
});
};
It's from here: http://howtonode.org/node-redis-fun.
I don't quite understand what's going on. From example, I figured that the Redis client is a some kind of interface between the database and the programmer, but now it seems that they are creating a new client for each code submit (the app they are building in the tutorial is accepts code snippet submits and stores them in a database)!
Also, where are Redis databases stored? In the same directory as the script? How to I change that?
I'm using Redis with Node.js.