Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-dataloader

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-dataloader - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

33

index.js

@@ -108,12 +108,27 @@ 'use strict';

load(key) {
return Q(this.loader.load(key));
return key ?
Q(this.loader.load(key)) :
Q.reject(new TypeError('key parameter is required'));
}
loadMany(keys) {
return Q(this.loader.loadMany(keys));
return keys ?
Q(this.loader.loadMany(keys)) :
Q.reject(new TypeError('keys parameter is required'));
}
prime(key, val) {
return rSetAndGet(this.keySpace, key, val, this.opt)
.then(resp => this.loader.clear(key).prime(key, resp));
if(!key) {
return Q.reject(new TypeError('key parameter is required'));
}
else if(val === undefined) {
return Q.reject(new TypeError('value parameter is required'));
}
else {
return rSetAndGet(this.keySpace, key, val, this.opt)
.then(r => {
this.loader.clear(key)
.prime(key, r === '' ? null : r);
});
}
}

@@ -124,6 +139,14 @@

rDel(this.keySpace, key).then(() => this.loader.clear(key)) :
Q.reject(new Error('Key parameter is required'));
Q.reject(new TypeError('key parameter is required'));
}
clearAllLocal() {
return Q(this.loader.clearAll());
}
clearLocal(key) {
return Q(this.loader.clear(key));
}
};
};

2

package.json
{
"name": "redis-dataloader",
"version": "0.2.0",
"version": "0.3.0",
"description": "DataLoader Using Redis as a Cache",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -53,2 +53,3 @@ # Redis Dataloader

- dataloader results must be either `null` or a JSON object.
- two functions: `clearLocal(key)` and `clearAllLocal()` allow you to clear the local cache only.

@@ -55,0 +56,0 @@ ### Instantiation

@@ -17,2 +17,6 @@ 'use strict';

this.rSet = (k, v) => Q.Promise((resolve, reject) => redis.set(
k, v, (err, resp) => err ? reject(err) : resolve(resp)
));
this.keySpace = 'key-space';

@@ -61,2 +65,9 @@ this.data = {

it('should require key', done => {
this.loader.load().catch(err => {
expect(err).to.be.instanceof(TypeError);
done();
}).done();
});
it('should use local cache on second load', done => {

@@ -170,2 +181,17 @@ this.stubs.redisMGet = sinon.stub(redis, 'mget', (keys, cb) => {

});
it('should handle empty array', done => {
this.loader.loadMany([])
.then(results => {
expect(results).to.deep.equal([]);
done();
}).done();
});
it('should require array', done => {
this.loader.loadMany().catch(err => {
expect(err).to.be.instanceof(TypeError);
done();
}).done();
});
});

@@ -191,2 +217,26 @@

});
it('should require key', done => {
this.loader.prime(undefined, { new: 'value' })
.catch(err => {
expect(err).to.be.instanceof(TypeError);
done();
}).done();
});
it('should require value', done => {
this.loader.prime('json').catch(err => {
expect(err).to.be.instanceof(TypeError);
done();
}).done();
});
it('should allow null for value', done => {
this.loader.prime('json', null)
.then(() => this.loader.load('json'))
.then(data => {
expect(data).to.be.null;
done();
}).done();
});
});

@@ -209,3 +259,3 @@

.catch(err => {
expect(err.message).to.equal('Key parameter is required');
expect(err).to.be.instanceof(TypeError);
done();

@@ -215,2 +265,38 @@ }).done();

});
describe('clearAllLocal', () => {
it('should clear all local in-memory cache', done => {
this.loader.loadMany(['json', 'null'])
.then(() => this.loader.clearAllLocal())
.then(() => this.rSet(
`${this.keySpace}:json`, JSON.stringify({ new: 'valeo' })
))
.then(() => this.rSet(
`${this.keySpace}:null`, JSON.stringify({ foo: 'bar' })
))
.then(() => this.loader.loadMany(['null', 'json']))
.then(data => {
expect(data).to.deep.equal([{ foo: 'bar' }, { new: 'valeo' }]);
done();
}).done();
});
});
describe('clearLocal', () => {
it('should clear local cache for a specific key', done => {
this.loader.loadMany(['json', 'null'])
.then(() => this.loader.clearLocal('json'))
.then(() => this.rSet(
`${this.keySpace}:json`, JSON.stringify({ new: 'valeo' })
))
.then(() => this.rSet(
`${this.keySpace}:null`, JSON.stringify({ foo: 'bar' })
))
.then(() => this.loader.loadMany(['null', 'json']))
.then(data => {
expect(data).to.deep.equal([null, { new: 'valeo' }]);
done();
}).done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc