You can use the .select(db, callback) function in node_redis.
var redis = require('redis'), db = redis.createClient(); db.select(1, function(err,res){ // you'll want to check that the select was successful here // if(err) return err; db.set('key', 'string'); // this will be posted to database 1 rather than db 0 });
If you use expressjs, you can set the development environment and production environment variable to automatically set which database you are using.
var express = require('express'), app = express.createServer(); app.configure('development', function(){
Then you can make one call to db.select() and set the parameters for production or development .
db.select(app.get('redisdb'), function(err,res){
Further information on dev / production in expressjs: http://expressjs.com/guide.html#configuration
The node_redis .select(db, callback) function will return OK in the second argument if a database is selected. An example of this can be seen in the Usage section of node_redis riya .
slickplaid
source share