0.0.2 • Published 8 years ago

nbp-adapter-memcached v0.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

Memcached adapter

This is a Memcached adapter for Node.js Bot Platform.

import memcachedAdapterFactory from 'nbp-adapter-memcached';
const memcachedAdapter = memcachedAdapterFactory({
    address: 'localhost',
    port: '11211',
    platform: 'your-platform-name'
});

Then you can pass entryId (can be you FB Page ID) and senderId (user ID) and recieve memcached instance:

const memcached = memcachedAdapter({
    entryId: 'fb-page-id',
    senderId: 'user-id'
});

memcached.get('key').then(value => {});
// or
const value = yield memcached.get('key');

Here are basic available methods:

  • get(KEY) – get KEY value;
  • del(KEY) – remove KEY value;
  • set(KEY, VALUE, [LIFETIME]) – set VALUE to the key KEY with LIFETIME in ms, by default LIFETIME is 2 hours;
  • getMulti([ KEY1, KEY2, KEY3 ]) – get an object with shape: { KEY1: VALUE1, KEY2: VALUE2, KEY3: VALUE3 }.

Please, look at usage example.

Tunneling

Check tunneling.js. To bind context of all client's function we need to perform tunneling on each request, so inside skills you can do memcached.set('Some text) without specifying application tokens, with suffixes (platform.entryId.senderId.key) for keys.

Look at router-builder.js as an example.