从 node.js 访问 memcached 的简单方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6233832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easy way for accessing memcached from node.js
提问by Ezequiel
I want to know if there is a good driver or native implementation to connect node.js directly to memcached.
我想知道是否有一个好的驱动程序或本机实现可以将 node.js 直接连接到 memcached。
回答by Andrey Lushnikov
Here's my experience of using couple of node-memcached modules
这是我使用几个 node-memcached 模块的经验
3rd-Eden/node-memcached. The project doesn't seem to be stable and has bugs with storing BLOBS (see issue #46and issue #48for details). Moreover I found it's code quite hard to read (and thus hard to update), so I wouldn't suggest using it in your projects.
elbart/node-memcacheseems to work fine, and I feel good about the way it's source code is written, but it doesn't support storing BLOBs (there's a forkthat is said to add the ability, but I haven't tested it)
overclocked/mcis the one I like a lot. This is the only one that is capable of storing BLOBs. It has nice documentation, its code looks good and it is easy-to-use.
第三个伊甸园/节点内存缓存。该项目似乎不稳定,并且在存储 BLOBS 时存在错误(有关详细信息,请参阅问题 #46和问题 #48)。此外,我发现它的代码很难阅读(因此很难更新),所以我不建议在您的项目中使用它。
elbart/node-memcache似乎工作正常,我对它编写源代码的方式感觉很好,但它不支持存储 BLOB(据说有一个fork可以添加此功能,但我还没有测试过) )
超频/mc是我非常喜欢的。这是唯一一种能够存储 BLOB 的方法。它有很好的文档,它的代码看起来不错并且易于使用。
Currently I use overclocked/mcin my projectand everything seems to be working fine.
回答by Josh
Use the search on: https://npmjs.org/
使用搜索:https: //npmjs.org/
If you don't have npm, install it.
如果您没有 npm,请安装它。
On the cli:
在 cli 上:
npm search memcache
npm 搜索内存缓存
Brings up 5 modules.
带来5个模块。
This seems to be the most popular: https://github.com/3rd-Eden/node-memcached
这似乎是最受欢迎的:https: //github.com/3rd-Eden/node-memcached
回答by Soyoes
The basic idea.
基本思路。
net = require("net");
var client = net.connect({port: 11211, host:"localhost"},function() {
console.log('connected');
client.write('stats\r\n');
//OR other commands + "\r\n"
client.on('data', function(data) {
console.log(data.toString());
});
client.on('end', function() {
console.log('data fetched');
});
});
Also you can use net.createServer to make your own memory cache server to support additional requirements such as PERSISTENT YOUR CACHE DATA TO MYSQL.
你也可以使用 net.createServer 来制作你自己的内存缓存服务器来支持额外的要求,比如PERSISTENT YOUR CACHE DATA TO MYSQL。

