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.5.0 to 1.0.2

.github/workflows/npm-publish.yml

12

index.js
const _ = require('lodash');
const Promise = require('bluebird');
const DataLoader = require('dataloader');
const stringify = require('json-stable-stringify');
const IORedis = require('ioredis');
const mapPromise = (promise, fn) => Promise.all(promise.map(fn));
module.exports = fig => {
const redis = fig.redis;
const isIORedis = redis instanceof IORedis;
const isIORedis = redis.constructor.name !== 'RedisClient';

@@ -39,3 +39,3 @@ const parse = (resp, opt) =>

const makeKey = (keySpace, key, cacheKeyFn) =>
`${keySpace}:${cacheKeyFn(key)}`;
`${keySpace ? keySpace + ':' : ''}${cacheKeyFn(key)}`;

@@ -78,3 +78,3 @@ const rSetAndGet = (keySpace, key, rawVal, opt) =>

? reject(err)
: Promise.map(results, r => parse(r, opt)).then(resolve);
: mapPromise(results, r => parse(r, opt)).then(resolve);
}

@@ -107,3 +107,3 @@ )

rMGet(this.keySpace, keys, this.opt).then(results =>
Promise.map(results, (v, i) => {
mapPromise(results, (v, i) => {
if (v === '') {

@@ -110,0 +110,0 @@ return Promise.resolve(null);

{
"name": "redis-dataloader",
"version": "0.5.0",
"version": "1.0.2",
"description": "DataLoader Using Redis as a Cache",
"main": "index.js",
"scripts": {
"test": "gulp test"
"test": "mocha test/**/*.unit.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/DubFriend/redis-dataloader.git"
"url": "git+ssh://git@github.com/PatrickJS/redis-dataloader.git"
},
"keywords": [
"GraphQL",
"DataLoader",

@@ -20,12 +21,13 @@ "Cache",

],
"author": "Brian Detering",
"contributors": [
"Brian Detering <BDeterin@gmail.com>",
"PatrickJS <github@patrickjs.com>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/DubFriend/redis-dataloader/issues"
"url": "https://github.com/PatrickJS/redis-dataloader/issues"
},
"homepage": "https://github.com/DubFriend/redis-dataloader#readme",
"homepage": "https://github.com/PatrickJS/redis-dataloader#readme",
"dependencies": {
"bluebird": "^3.5.0",
"dataloader": "^1.2.0",
"ioredis": "^3.1.2",
"json-stable-stringify": "^1.0.1",

@@ -37,8 +39,7 @@ "lodash": "^4.17.2"

"chai-as-promised": "^7.1.1",
"gulp": "^3.9.1",
"gulp-mocha": "^3.0.1",
"ioredis": "^3.1.2",
"mocha": "^8.1.1",
"redis": "^2.6.3",
"redis-mock": "^0.51.0",
"sinon": "^1.17.6"
}
}
require('./test')({
name: 'with driver "redis"',
redis: require('redis').createClient(),
redis: require('redis-mock').createClient(),
});
const _ = require('lodash');
const Promise = require('bluebird');
const chai = require('chai');

@@ -10,2 +9,4 @@ chai.use(require('chai-as-promised'));

const mapPromise = (promise, fn) => Promise.all(promise.map(fn));
module.exports = ({ name, redis }) => {

@@ -28,3 +29,3 @@ const RedisDataLoader = createRedisDataLoader({ redis });

new Promise((resolve, reject) => {
redis.get(k, (err, resp) => (err ? rejecte(err) : resolve(resp)));
redis.get(k, (err, resp) => (err ? reject(err) : resolve(resp)));
});

@@ -55,7 +56,7 @@

this.userLoader = () =>
new DataLoader(keys => Promise.map(keys, this.loadFn), {
new DataLoader(keys => mapPromise(keys, this.loadFn), {
cache: false,
});
return Promise.map(
return mapPromise(
_.keys(this.data).concat(['{"a":1,"b":2}', '[1,2]']),

@@ -194,8 +195,6 @@ k => rDel(`${this.keySpace}:${k}`)

done();
})
.done();
});
}, 1100);
})
.catch(done)
.done();
.catch(done);
});

@@ -214,2 +213,18 @@

});
it('should handle optional keySpace', () => {
this.stubs.redisMGet = sinon.stub(redis, 'mget', (keys, cb) => {
cb(null, [JSON.stringify(this.data.json)]);
});
const loader = new RedisDataLoader(null, this.userLoader());
return loader
.load('foo')
.then(_ => {
expect(this.stubs.redisMGet.args[0][0]).to.deep.equal([
'foo',
]);
});
});
});

@@ -216,0 +231,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