Skip to content

Commit 1512ec5

Browse files
Johan KanefurPatrickJS
authored andcommitted
Add support for optional keySpace name
1 parent fc29b54 commit 1512ec5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = fig => {
3636
};
3737

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

4141
const rSetAndGet = (keySpace, key, rawVal, opt) =>
4242
toString(rawVal, opt).then(

test/test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = ({ name, redis }) => {
2424

2525
this.rGet = k =>
2626
new Promise((resolve, reject) => {
27-
redis.get(k, (err, resp) => (err ? rejecte(err) : resolve(resp)));
27+
redis.get(k, (err, resp) => (err ? reject(err) : resolve(resp)));
2828
});
2929

3030
this.keySpace = 'key-space';
@@ -207,6 +207,22 @@ module.exports = ({ name, redis }) => {
207207
expect(data.getTime()).to.equal(100);
208208
});
209209
});
210+
211+
it('should handle optional keySpace', () => {
212+
this.stubs.redisMGet = sinon.stub(redis, 'mget', (keys, cb) => {
213+
cb(null, [JSON.stringify(this.data.json)]);
214+
});
215+
216+
const loader = new RedisDataLoader(null, this.userLoader());
217+
218+
return loader
219+
.load('foo')
220+
.then(_ => {
221+
expect(this.stubs.redisMGet.args[0][0]).to.deep.equal([
222+
'foo',
223+
]);
224+
});
225+
});
210226
});
211227

212228
describe('loadMany', () => {

0 commit comments

Comments
 (0)