您可以
.select(db, callback)在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});如果您使用的是expressjs,则可以设置开发和生产环境变量来自动设置要使用的数据库。
var express = require('express'), app = express.createServer();app.configure('development', function(){ // development options go here app.set('redisdb', 5);});app.configure('production', function(){ // production options here app.set('redisdb', 0);});然后您可以打一个电话,
db.select()并为
production或设置选项
development。
db.select(app.get('redisdb'), function(err,res){ // app.get will return the value you set above // do something here});有关expressjs中的开发/生产的更多信息:http
://expressjs.com/guide.html#configuration
该
node_redis
.select(db,callback)如果选择数据库回调函数将在第二个参数返回OK。可以在node_redis自述文件的“
用法”部分中看到此示例。



