Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

elbart/node-memcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node.js memcached client

A pure-JavaScript Memcache library for node.

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 = 'loalhost';

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
});

After connecting, you can start to make requests.

client.get('key', function(response){
	
});

client.set('key', 'value', function(response){

	// response will be 'STORED' if it worked,
	// else an error (huh?)

	// lifetime argument is optional

}, lifetime);

client.del('key', function(response){

	// delete a key from cache.
	// response?
});

client.version(function(response)){

	// response contains server version?
});

client.increment('key', value, function(response){
});
client.decrement('key', value, function(response){
});

Once you're done, close the connection.

client.close();

About

node.js memcached client

Resources

Stars

Watchers

Forks

Packages

No packages published