Skip to content

Commit

Permalink
Merge pull request #91 from hapijs/cache-false
Browse files Browse the repository at this point in the history
allow to store boolean false
  • Loading branch information
marcuspoehls committed Sep 7, 2018
2 parents 9dece84 + 1303a9a commit bfa7e94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/index.js
Expand Up @@ -140,9 +140,7 @@ internals.Connection.prototype.get = async function (key) {
throw Error('Bad envelope content');
}

if ((!envelope.item && envelope.item !== 0) ||
!envelope.stored) {

if (!envelope.stored || !envelope.hasOwnProperty('item')) {
throw Error('Incorrect envelope structure');
}

Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Expand Up @@ -787,6 +787,25 @@ describe('Redis', () => {
const result = await redis.get(key);
expect(result.item).to.equal(0);
});

it('can store and retrieve falsy values such as boolean false', async () => {

const options = {
host: '127.0.0.1',
port: 6379,
partition: 'wwwtest'
};
const key = {
id: 'test',
segment: 'test'
};

const redis = new Redis(options);
await redis.start();
await redis.set(key, false, 200);
const result = await redis.get(key);
expect(result.item).to.equal(false);
});
});

describe('set()', () => {
Expand Down

0 comments on commit bfa7e94

Please sign in to comment.