![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
node_memcached
Advanced tools
这是一个为 node.js 开发的 memcached 客户端,使用二进制传输协议,支持 SASL 鉴权。特别针对阿里云 OCS 进行优化。
安装:
npm install node_memcached
var PORT = 11211;
var HOST = '127.0.0.1';
var username = 'myname';
var password = 'mypass';
var memcached = require("node_memcached");
var client = memcached.createClient(PORT, HOST, {
username: username,
password: password
});
client.on("error", function (err) {
console.log("Error " + err);
});
// 10 为过期时间, 10秒
client.set('hello', 'world', 10);
client.get('hello', 'world', function(err, res) {
console.log(err, res);
});
// 也可以不用设置过期时间
client.set('number', 1);
client.increment('number', 2);
client.decrement('number', 1);
client.get('number', function(err, res) {
console.log(err, res);
});
client
会发送以下事件.
client
在与 memcached 服务器建立连接后发送 'connect' 事件, 但并不代表 client
已经可以向 memcached 发送命令。
client
在发送 connect
事件后, 如果设置了 username 和 password,那么将在 SASL 鉴权 成功后发送 ready
事件,
否则会立即发送 ready
事件。 在 ready
事件之前,所有的命令都会被加入队列,一旦 ready
发送, 这些命令将会依次执行。
client
会在遇到无法处理的错误时发送 error
事件。
注意,在 node 中 error
是一个特殊的事件,如果 cliet
发送了这个事件而没有被侦听,那么将会导致 node 进程退出。因此
你应该在创建 client
的时候主动侦听该事件并作出相应处理。例如:
var client = Memcached.createClient();
client.on('error', function(err) {
log('Error', err)
})
client
会在与 memcached 断开连接后发送 end
事件。
client
will emit drain
when the TCP connection to the Redis server has been buffering, but is now
writable. This event can be used to stream commands in to Redis and adapt to backpressure. Right now,
you need to check client.command_queue.length
to decide when to reduce your send rate. Then you can
resume sending when you get drain
.
client
会在与 memcached 服务器连接的 stream 可
redis.createClient() = redis.createClient(PORT, HOST);
redis.createClient() = redis.createClient(PORT, HOST, { username: '', password: '' })
PORT
: memcached 服务器的端口号,默认为 11211HOST
: memcached 服务器的 IP 地址,默认为 127.0.0.1username
: 如果设置了该项,则启用 SASL 鉴权,否则直接连接 memcached 服务器。password
: 如果设置了该项,则启用 SASL 鉴权,否则直接连接 memcached 服务器。createClient()
将返回一个 MemcachedClient
对象.
强制关闭 client
与 memcached 服务器之间的连接。
在 client
断开连接后,如果开发者没有调用 client.end(),则 client
将会自动尝试重新连接 memcached 服务器,初始延时为 150ms,
重连失败后延时加长,最长为 1 分钟并且会持续尝试直到连接成功。
在运行 node 之前输出环境变量 DEBUG=node_memcached 将会打印调试信息。
FAQs
Memcached client library
The npm package node_memcached receives a total of 0 weekly downloads. As such, node_memcached popularity was classified as not popular.
We found that node_memcached demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.