lol-js
Version:
Node.js bindings for the Riot API, with caching and rate limiting
48 lines (38 loc) • 1.17 kB
JavaScript
// Generated by CoffeeScript 1.9.2
(function() {
var RedisCache, ld, redis;
ld = require('lodash');
redis = require('redis');
module.exports = RedisCache = (function() {
function RedisCache(options) {
options = ld.defaults({}, options, {
host: '127.0.0.1',
port: 6379,
keyPrefix: 'loljs-'
});
this.keyPrefix = options.keyPrefix;
this.client = redis.createClient(options.port, options.host);
}
RedisCache.prototype.get = function(params, done) {
return this.client.get(this.keyPrefix + "-" + params.key, function(err, answer) {
if (err != null) {
return done(err);
}
answer = JSON.parse(answer);
return done(null, answer);
});
};
RedisCache.prototype.set = function(params, value) {
var key;
key = this.keyPrefix + "-" + params.key;
this.client.set(key, JSON.stringify(value));
if (params.ttl != null) {
return this.client.expire(key, params.ttl);
}
};
RedisCache.prototype.destroy = function() {
return this.client.quit();
};
return RedisCache;
})();
}).call(this);