node-redis 有人做过长连接或者连接池吗?
官方推荐用法如下,但是是个短链接,抓包已能确认,非常影响性能。有大侠自己改过长连接或者连接池吗?如何避免变量污染的问题? var redis = require("redis"), client = redis.createClient();
// if you'd like to select database 3, instead of 0 (default), call
// client.select(3, function() { /* ... */ });
client.on("error", function (err) {
console.log("Error " + err);
});
client.set("string key", "string val", redis.print);
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();
});
8 回复
没有重新连接吧... 最近刚好在看ioredis,是在createClient的时候构造了一个连接,然后其他操作都只是在stream上面write的buffer。。 get和set的测试对比来看node_redis不应该是短连接形式的。
https://github.com/luin/ioredis 这里有计划搞连接池,看 roadmap 部分。不过 redis 随便一用都有 10万ops每秒吧。 你们的场景量好大啊