Skip to content

Commit

Permalink
added hmget feature (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Jun 26, 2016
1 parent f0cac84 commit 56675c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/commands/hmget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function hmget(key, ...fields) {
return fields.map(field => this.data[key][field] || null);
}
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
17 changes: 17 additions & 0 deletions test/commands/hmget.js
Original file line number Diff line number Diff line change
@@ -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: '[email protected]' },
},
});
return redis.hmget('user:1', 'id', 'email', 'location')
.then(values => expect(values).toEqual([
'1', '[email protected]', null,
]));
});
});

0 comments on commit 56675c9

Please sign in to comment.