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.4.2 to 0.5.0

8

index.js

@@ -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 === '') {

2

package.json
{
"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 @@

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