trooba-memcached-transport

0.1.0 • Public • Published

trooba-memcached-transport

codecov Build Status NPM Downloads Known Vulnerabilities

A Memcached transport for trooba pipeline. All APIs of Memcached are supported in this transport.

Installation

npm install trooba-memcached-transport --save

Usage

var memcachedTransport = require('trooba-memcached-transport');    
 
const client = require('trooba')
                .use(memcachedTransport, {
                clientId: 'dev-memcached',
                servers: [ 
                    'memcached1.dev.myorg.com:11211',
                    'memcached2.dev.myorg.com:11211'],
                })
                .build()
                .create('client');
 
await client.set('test-key','test value', 0});
const retrievedValue = await client.get('test-key' );
console.log(retrievedValue);
 

Get Involved

  • Contributing: Pull requests are welcome!
  • Support: Join our gitter chat to ask questions to get support from the maintainers and other Trooba developers

Setting up memcached client

You can setup memcached client by configuring three properties clientId, servers and options.

  • clientid - an unique identifier associated with memcached client.
  • servers - location of memcached servers. Please refer to the documentation here on various ways to configure server locations.
  • options - various options to configure the connection. Please refere to the documentation here for various options to configure.
const configs = {
                clientId: '<an unique id>',
                servers: '<location of memcached servers>',
                options: '<options to configure the client>'               
                };
 
const client = require('trooba')
                .use(memcachedTransport, configs)
                .build()
                .create('client');

API

client.touch Touches the given key.

  • key: String The key
  • lifetime: Number After how long should the key expire measured in seconds
await client.touch('key', 10);

client.get Get the value for the given key.

  • key: String, the key
const data = await client.get('foo')
console.log(data);

client.gets Get the value and the CAS id.

  • key: String, the key
const data = await client.gets('foo');
console.log(data.foo);
console.log(data.cas);

client.getMulti Retrieves a bunch of values from multiple keys.

  • keys: Array, all the keys that needs to be fetched
const data = await client.getMulti(['foo', 'bar']);
console.log(data.foo);
console.log(data.bar);

client.set Stores a new value in client.

  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be stored measured in seconds
client.set('foo', 'bar', 10);

client.replace Replaces the value in client.

  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds
await client.replace('foo', 'bar', 10);

client.add Add the value, only if it's not in client already.

  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds
await client.add('foo', 'bar', 10);

client.cas Add the value, only if it matches the given CAS value.

  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds
  • cas: String the CAS value
const data = await client.gets('foo');
await client.cas('foo', 'bar', data.cas, 10);

client.append Add the given value string to the value of an existing item.

  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
await client.append('foo', 'bar');

client.prepend Add the given value string to the value of an existing item.

  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
await client.prepend('foo', 'bar');

client.incr Increment a given key.

  • key: String the name of the key
  • amount: Number The increment
await client.incr('foo', 10);

client.decr Decrement a given key.

  • key: String the name of the key
  • amount: Number The increment
await client.decr('foo', 10);

client.del Remove the key from client.

  • key: String the name of the key
await client.del('foo');

client.version Retrieves the version number of your server.

client.flush Flushes the client server.

client.stats Retrieves stats from your client server.

client.settings Retrieves your stats settings.

client.slabs Retrieves stats slabs information.

client.items Retrieves stats items information.

client.end Closes all active client connections.

Package Sidebar

Install

npm i trooba-memcached-transport

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

30.6 kB

Total Files

14

Last publish

Collaborators

  • dimichgh
  • gmunisifreddy