Skip to content

Instantly share code, notes, and snippets.

@jkantr
Forked from hmpmarketing/memcached.js
Last active January 5, 2018 17:46
Show Gist options
  • Save jkantr/ae356a2828f9182d1e0902af00e52707 to your computer and use it in GitHub Desktop.
Save jkantr/ae356a2828f9182d1e0902af00e52707 to your computer and use it in GitHub Desktop.
const Promise = require('bluebird');
const memcache = require('./memcached.js');
const lifetime = 100 // i don't actually know what this is.. fill in the correct thing :p
Promise.try(() => {
return memcache.add('foo', 'bar', lifetime);
}).then(() => {
return memcache.get('foo');
}).then((foo) => {
console.log(foo) // should be 'bar' i imagine...
})
const Promise = require('bluebird');
const Memcached = require('memcached');
const memcached = new Memcached('memcacheserver:11211');
Promise.promisifyAll(memcached);
memcached.on('issue', details => console.log('issue: ', details))
memcached.on('failure', details => console.log('failure: ', details))
memcached.on('reconnecting', details => console.log('reconnecting: ', details))
memcached.on('reconnect', details => console.log('reconnect: ', details))
memcached.on('remove', details => console.log('remove: ', details))
const Cache = {}
Cache.add = function (key, value, lifetime) {
return memcached.setAsync(key, value, lifetime);
};
Cache.get = function (key) {
return memcached.getAsync(key)
};
module.exports = Cache;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment