simplecached

Simplified memcached server.

simplecached

Simplified version of memcached, useful for didactic purposes.

Just run:

npm install simplecached

or add it to your dependencies in package.json:

"dependencies": {
    "simplecached": "*",
    ...
},

To start a server, just require simplecached and create a server:

var simplecached = require('simplecached');
var server = simplecached.Server();

To start the server on a port different than the default (11311), add it to the Server constructor:

var server = simplecached.Server(port);

Also a callback can be added to be notified when the server has started:

var server = simplecached.Server(port, function(error, result) {
    console.log('Server started');
});

To stop the server, call close() on it:

server.close();

To create a client for a simplecached server, just create it.

var simplecached = require('simplecached');
var client = simplecached.Client();

The following functions can be called on the client.

Get a key from the remote simplecached. The callback is a function(error, result) that will be called either with an error or the result, or null if the value was not found.

Set a value into the remote simplecached. The callback is a function(error, result) that will be called with an error or a result. The result can be true if the value was stored, false otherwise.

Delete a value from the remote simplecached. The callback is a function(error, result) that will be called with an error or a result. The result can be true if the value was deleted, false if not found.

Close the connection. The optional callback will be called after the connection is actually closed.

The line protocol for simplecached is a simplified version of memcached's.

Gets a key from the cache. The response can be either:

VALUE <value>\r\n

when a value is found, or

END\r\n

if the value was not found.

Sets a value in the cache, always a string (without line feeds). The response can be either:

STORED\r\n

if the value was stored, or

NOT_STORED\r\n

otherwise.

Deletes a value from the cache. The response can be either:

DELETED\r\n

if the value was stored, or

NOT_FOUND\r\n

otherwise.

Close the connection.

Simplecached is licensed under the MIT license. Please consult the LICENSE file for details.