diff --git a/src/commands/hmget.js b/src/commands/hmget.js new file mode 100644 index 000000000..4ef7c44f1 --- /dev/null +++ b/src/commands/hmget.js @@ -0,0 +1,3 @@ +export function hmget(key, ...fields) { + return fields.map(field => this.data[key][field] || null); +} diff --git a/src/commands/index.js b/src/commands/index.js index 992832e1e..0618186ef 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -7,6 +7,7 @@ export * from './get'; export * from './getset'; export * from './hget'; export * from './hgetall'; +export * from './hmget'; export * from './hmset'; export * from './hset'; export * from './hsetnx'; diff --git a/test/commands/hmget.js b/test/commands/hmget.js new file mode 100644 index 000000000..4768af15b --- /dev/null +++ b/test/commands/hmget.js @@ -0,0 +1,17 @@ +import expect from 'expect'; + +import MockRedis from '../../src'; + +describe('hmget', () => { + it('should return the values of specified keys in a hash map', () => { + const redis = new MockRedis({ + data: { + 'user:1': { id: '1', email: 'bruce@wayne.enterprises' }, + }, + }); + return redis.hmget('user:1', 'id', 'email', 'location') + .then(values => expect(values).toEqual([ + '1', 'bruce@wayne.enterprises', null, + ])); + }); +});