node-memcache

node.js memcached client

  • 所有者: elbart/node-memcache
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

node.js memcached client

A pure-JavaScript memcached library for node.

Tests

To run the test suite, first insall expresso,
then run make test.

If you have node-jscoverage you can
also make test-cov for coverage, but that's pretty nerdy.

Usage

Create a Client object to start working.
Host and port can be passed to the constructor or set afterwards.
They have sensible defaults.

var memcache = require('./memcache');

var client = new memcache.Client(port, host);
client.port = 11211;
client.host = 'localhost';

The Client object emits 4 important events - connect, close, timeout and error.

client.on('connect', function(){
	// no arguments - we've connected
});

client.on('close', function(){
	// no arguments - connection has been closed
});

client.on('timeout', function(){
	// no arguments - socket timed out
});

client.on('error', function(e){
	// there was an error - exception is 1st argument
});

// connect to the memcache server after subscribing to some or all of these events
client.connect()

After connecting, you can start to make requests.

client.get('key', function(error, result){

	// all of the callbacks have two arguments.
	// 'result' may contain things which aren't great, but
	// aren't really errors, like 'NOT_STORED'

});

client.set('key', 'value', function(error, result){

	// lifetime is optional. the default is
	// to never expire (0)

}, lifetime);

client.delete('key', function(error, result){

	// delete a key from cache.
});

client.version(function(error, result)){

	// grab the server version
});

There are all the commands you would expect.

// all of the different "store" operations
// (lifetime & flags are both optional)
client.set(key, value, callback, lifetime, flags);
client.add(key, value, callback, lifetime, flags);
client.replace(key, value, callback, lifetime, flags);
client.append(key, value, callback, lifetime, flags);
client.prepend(key, value, callback, lifetime, flags);
client.cas(key, value, unique, callback, lifetime, flags);

// increment and decrement (named differently to the server commands - for now!)
// (value is optional, defaults to 1)
client.increment('key', value, callback);
client.decrement('key', value, callback);

// statistics. the success argument to the callback
// is a key=>value object
client.stats(callback);
client.stats('settings', callback);
client.stats('items', callback);
client.stats('mongeese', callback);

Once you're done, close the connection.

client.close();

There might be bugs. I'd like to know about them.

I bet you also want to read the memcached
protocol doc. It's exciting! It also explains possible error messages.

主要指標

概覽
名稱與所有者elbart/node-memcache
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證
所有者活动
創建於2010-01-16 09:19:11
推送於2018-12-04 00:39:33
最后一次提交2012-12-30 02:15:29
發布數1
最新版本名稱0.1.0 (發布於 )
第一版名稱0.1.0 (發布於 )
用户参与
星數285
關注者數15
派生數63
提交數81
已啟用問題?
問題數24
打開的問題數15
拉請求數7
打開的拉請求數11
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?