Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.47 KB

README.MD

File metadata and controls

38 lines (29 loc) · 1.47 KB

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.