Skip to content

Commit 334a960

Browse files
author
Jonathan Muller
committed
Merge branch 'release/0.3.1'
2 parents 58ee7a4 + d338b41 commit 334a960

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function redisStore(args) {
180180
cb = options;
181181
options = {};
182182
}
183+
options = options || {};
183184
options.parse = true;
184185

185186
var compress = (options.compress || options.compress === false) ? options.compress : redisOptions.compress;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cache-manager-redis",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Redis store for the node-cache-manager",
55
"main": "index.js",
66
"scripts": {

test/lib/redis-store-spec.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,18 @@ describe('wrap function', function () {
471471
}, 100);
472472
}
473473

474-
var userId = 123;
474+
// Simulate retrieving a user from a database with Promise
475+
function getUserPromise(id) {
476+
return new Promise(function (resolve) {
477+
setTimeout(function () {
478+
resolve({ id: id });
479+
}, 100);
480+
});
481+
}
475482

476483
it('should be able to cache objects', function (done) {
484+
var userId = 123;
485+
477486
// First call to wrap should run the code
478487
redisCache.wrap('wrap-user', function (cb) {
479488
getUser(userId, cb);
@@ -489,4 +498,26 @@ describe('wrap function', function () {
489498
});
490499
});
491500
});
501+
502+
it('should work with promises', function () {
503+
var userId = 123;
504+
505+
// First call to wrap should run the code
506+
return redisCache
507+
.wrap('wrap-promise', function () {
508+
return getUserPromise(userId);
509+
})
510+
.then(function (user) {
511+
assert.equal(user.id, userId);
512+
513+
// Second call to wrap should retrieve from cache
514+
return redisCache
515+
.wrap('wrap-promise', function () {
516+
return getUserPromise(userId+1);
517+
})
518+
.then(function (user) {
519+
assert.equal(user.id, userId);
520+
});
521+
});
522+
});
492523
});

test/lib/redis-store-zlib-spec.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,66 @@ describe('Compression Tests', function () {
283283
});
284284
});
285285
});
286+
287+
describe('wrap function', function () {
288+
289+
// Simulate retrieving a user from a database
290+
function getUser(id, cb) {
291+
setTimeout(function () {
292+
cb(null, { id: id });
293+
}, 100);
294+
}
295+
296+
// Simulate retrieving a user from a database with Promise
297+
function getUserPromise(id) {
298+
return new Promise(function (resolve) {
299+
setTimeout(function () {
300+
resolve({ id: id });
301+
}, 100);
302+
});
303+
}
304+
305+
it('should be able to cache objects', function (done) {
306+
var userId = 123;
307+
308+
// First call to wrap should run the code
309+
redisCompressCache.wrap('wrap-compress', function (cb) {
310+
getUser(userId, cb);
311+
}, function (err, user) {
312+
assert.equal(user.id, userId);
313+
314+
// Second call to wrap should retrieve from cache
315+
redisCompressCache.wrap('wrap-compress', function (cb) {
316+
getUser(userId+1, cb);
317+
}, function (err, user) {
318+
assert.equal(user.id, userId);
319+
done();
320+
});
321+
});
322+
});
323+
324+
it('should work with promises', function () {
325+
var userId = 123;
326+
327+
// First call to wrap should run the code
328+
return redisCompressCache
329+
.wrap('wrap-compress-promise', function () {
330+
return getUserPromise(userId);
331+
})
332+
.then(function (user) {
333+
assert.equal(user.id, userId);
334+
335+
// Second call to wrap should retrieve from cache
336+
return redisCompressCache
337+
.wrap('wrap-compress-promise', function () {
338+
return getUserPromise(userId+1);
339+
})
340+
.then(function (user) {
341+
assert.equal(user.id, userId);
342+
});
343+
});
344+
});
345+
});
286346
});
287347

288348

0 commit comments

Comments
 (0)