初始化redis
//连接redis
var redis = require('redis'),
RDS_PORT = 6379, //端口号
RDS_HOST = '127.0.0.1', //服务器IP
RDS_OPTS = {}, //设置项
//RDS_PWD = 'porschev', //密码
//RDS_OPTS = {auth_pass:RDS_PWD}, //设置项
redClient = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);
//选择哪个库
redClient.select(1, function () {
console.log('连接redis库1');
})
redClient.on('ready', function (res) {
console.log('ready');
});
redClient.on('connect', function () {
redClient.set('Hello', 'Redis');
redClient.get('Hello', redis.print);
console.log('Hello');
});
一些常用操作命令
//删除list的元素
redClient.lrem('list', 0, value, function (err, res) {
if (err) {
console.log(err);
} else {
console.log(res);
}
});
//判断是否存在key
redClient.EXISTS(key, function (err, replay) {
if (err) return false;
return replay;
})
网友评论