Skip to content

Commit

Permalink
Add mget.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadaszewski committed Oct 22, 2021
1 parent 39891e2 commit 0a933a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/database/sqlite/redismock/string.js
Expand Up @@ -120,6 +120,24 @@ module.exports = function(RedisMock) {
});
}

Part.mget = function(...keys) {
if (!keys.length)
throw Error('Too few parameters');

return this.transaction((client, tablePrefix) => {
const stmt = client.prepare(`SELECT string_value FROM ${tablePrefix}string WHERE string_key=?;`);
const res = [];
for (const k of keys) {
const r = stmt.get(k);
if (!r)
res.push(null);
else
res.push(r['string_value']);
}
return res;
});
}

helpers.wrapFunctions(Part);
Object.assign(RedisMock, Part);
}
6 changes: 6 additions & 0 deletions src/database/sqlite/redismock/string_test.js
Expand Up @@ -111,4 +111,10 @@ describe('string_test', () => {
assert(await m.incr('s') === 2);
await m.del('s');
});

it('mget', async() => {
await m.set('s', 'foo');
assert.deepEqual(await m.mget('s', 's', 's'),
[ 'foo', 'foo', 'foo' ]);
});
});

0 comments on commit 0a933a3

Please sign in to comment.