Skip to content

Commit

Permalink
return null if list.pop has no results
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Feb 28, 2016
1 parent 1a04a50 commit b742bf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions initializers/cache.js
Expand Up @@ -215,6 +215,7 @@ module.exports = {
api.cache.pop = function(key, next){
api.redis.client.lpop(api.cache.redisPrefix + key, function(err, object){
if(err){ return next(err); }
if(!object){ return next(); }
var item = JSON.parse(object);
return next(null, item.data);
});
Expand Down
8 changes: 8 additions & 0 deletions test/core/cache.js
Expand Up @@ -232,6 +232,14 @@ describe('Core: Cache', function(){
});
});

it('will return null if the list is empty', function(done){
api.cache.pop('emptyListKey', function(error, data){
should.not.exist(error);
should.not.exist(data);
done();
});
});

it('can get the length of an array when full', function(done){
api.cache.push('testListKey2', 'a string', function(){
api.cache.listLength('testListKey2', function(error, l){
Expand Down

0 comments on commit b742bf1

Please sign in to comment.