2.0.0 • Published 4 years ago

notcached v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Notcached

A Node.js Memcached client.

After using the memcached package, I was dissatisfied. memcached does not support promises and its not maintained anymore. Even the fork memecached doesn't seem to be maintained either. So, I decided to write my own client instead.

Features

  • Basic commands, eg. get, set
  • Pool for a single server
  • Multiple server support with ketama algorithm
  • Meta commands
  • Binary support
  • SASL support
  • Stream support (node.js stream)

Documentations

Here.

Examples

const { Notcached, createPool } = require('notcached');
const MEMCACHED_SERVER_LOCATION = 'localhost:11211';

const client = new Notcached(SERVER_LOCATION, {
    debug: false, // can be boolean or a function. I recommend using boolean and listen to 'debug' event
    retries: 3,  // number of retries before giving up
    retryTime: 3000, // time in milliseconds to wait before the client attempt to reconnect
    timeout: Infinity, // socket timeout, better leave this Infinity
    connectionTimeout: 3000, // time in milliseconds the before client tries to reconnect
    tcp: {}, // tcp options. Usually you don't need to specify this
    legacyFlags: true // leave this to true for backwards compatibility. Please see FAQ
});

// make sure results are returned in strings
client.string();

// setting something
await client.set('hey', 'hello world!', 0, 12);

// getting something
const val = await client.get('hey');
console.log(val); // prints: { 'hey': { data: 'hello world!', flags: 12 } }

const pool = createPool(MEMCACHED_SERVER_LOCATION, { min: 2, max: 10 }); // the pool options accept tarn.js options

// you can directly do something with it 
pool.set('hey', 'hello world!');

// if you really need to manually acquire connection, you can access the pool at `pool.pool`
const connection = await pool.pool.acquire().promise;

// do things with this connection

// release it
pool.pool.release(pool);

This is some examples for common usages of the library. For more info, visit the documentation.

Please note that the pooling capabilities of this library comes from tarn.js. You should visit them for more examples on how to use the pool.

Memcached FAQ

Here.