NodeJS连接Redis:安装及开机自动启动设置
http://code.z01.com/v4 )
这里收集一些使用技巧和基本命令
start
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
# 为Redis添加权限,并设置开始自动运行
chmod u+x redis
update-rc.d -f redis defaults
# 测试一下
./redis start
在node.js中访问redis
需要先安装node_redis模块
npm install redis
基本用法
var redis = require("redis")
, client;
client = redis.createClient(6379, ‘127.0.0.1‘, {});
// 密码
client.auth(‘密码‘);
// 选择数据库,比如第3个数据库,默认是第0个
client.select(3, function() { /* … */ });
client.on("error", function (err) {
console.log("Error " + err);
});
// 设置键值
client.set("Testing", "string val", redis.print);
// 取值
client.get("Testing", function(err, replies) {
});
// 其它API
client.hset("hash key", "hashtest 1", "some value", redis.print);
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
client.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
client.quit();
});
// 枚举趣出数据库中的所有键
client.keys(‘*‘, function (err, keys) {
});
,220)/}
连接,自动,设置,JS,安装