redis-dataloader
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -99,14 +99,8 @@ const _ = require('lodash'); | ||
this.opt = _.pick(opt, customOptions) || {}; | ||
this.opt.cacheKeyFn = | ||
this.opt.cacheKeyFn || (k => (_.isObject(k) ? stringify(k) : k)); | ||
this.keySpace = ks; | ||
this.loader = new DataLoader( | ||
keys => | ||
rMGet( | ||
this.keySpace, | ||
_.map(keys, this.opt.cacheKeyFn), | ||
this.opt | ||
).then(results => | ||
rMGet(this.keySpace, keys, this.opt).then(results => | ||
Promise.map(results, (v, i) => { | ||
@@ -113,0 +107,0 @@ if (v === '') { |
{ | ||
"name": "redis-dataloader", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "DataLoader Using Redis as a Cache", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -62,3 +62,3 @@ # Redis Dataloader | ||
``` | ||
```javascript | ||
const redis = require('redis').createClient(); | ||
@@ -73,3 +73,3 @@ const RedisDataLoader = require('redis-dataloader')({ redis: redis }); | ||
``` | ||
```javascript | ||
const loader = new RedisDataLoader('<redis key prefix>', '<Facebook Dataloader>', '<Options>'); | ||
@@ -114,3 +114,3 @@ ``` | ||
``` | ||
```javascript | ||
const loader = new RedisDataLoader('prefix', new DataLoader(), { cache: false }); | ||
@@ -117,0 +117,0 @@ ``` |
@@ -7,8 +7,5 @@ const _ = require('lodash'); | ||
const sinon = require('sinon'); | ||
// const redis = require('redis').createClient(); | ||
const DataLoader = require('dataloader'); | ||
const createRedisDataLoader = require('../index'); | ||
// const RedisDataLoader = require('../index.js')({ redis }); | ||
module.exports = ({ name, redis }) => { | ||
@@ -234,2 +231,37 @@ const RedisDataLoader = createRedisDataLoader({ redis }); | ||
expect(this.loader.loadMany()).to.be.rejectedWith(TypeError)); | ||
it('should handle custom cacheKeyFn', () => { | ||
const loader = new RedisDataLoader(this.keySpace, this.userLoader(), { | ||
cacheKeyFn: key => `foo-${key}`, | ||
}); | ||
loader.loadMany(['json', 'null']).then(results => { | ||
expect(results).to.deep.equal([this.data.json, this.data.null]); | ||
}); | ||
}); | ||
it('should use local cache on second load when using custom cacheKeyFn', () => { | ||
this.stubs.redisMGet = sinon.stub(redis, 'mget', (keys, cb) => { | ||
cb(null, [JSON.stringify(this.data.json)]); | ||
}); | ||
const loader = new RedisDataLoader(this.keySpace, this.userLoader(), { | ||
cacheKeyFn: key => `foo-${key}`, | ||
}); | ||
return loader | ||
.loadMany(['json']) | ||
.then(data => { | ||
expect(this.loadFn.callCount).to.equal(0); | ||
expect(this.stubs.redisMGet.args[0][0]).to.deep.equal([ | ||
'key-space:foo-json', | ||
]); | ||
expect(this.stubs.redisMGet.callCount).to.equal(1); | ||
return loader.loadMany(['json']); | ||
}) | ||
.then(data => { | ||
expect(this.loadFn.callCount).to.equal(0); | ||
expect(this.stubs.redisMGet.callCount).to.equal(1); | ||
}); | ||
}); | ||
}); | ||
@@ -236,0 +268,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25453
486
0