您的位置:首页 > 数据库 > Redis

简单的node连接redis及操作

2016-03-09 15:30 555 查看
首先npm install redis

redis.js内容如下:

包括简单的set、get和del

var redis = require("redis"),

client = redis.createClient(6379,'localhost',{});

client.on("error", function (err) {
console.log("Error " + err);
});

exports.set=function(id,data){
client.set(id,JSON.stringify(data));

};

exports.get=function(id,callback){
client.get(id,function(err,reply,fields){
if(err) {throw  err;}
else {
return  callback(err, JSON.parse(reply), fields);
}

});
};
exports.del=function(id){
client.del(id);
};


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: