Skip to content

Commit

Permalink
Add support for keys command (#92)
Browse files Browse the repository at this point in the history
@pivotal-csaa thanks! 👍
  • Loading branch information
pivotal-csaa authored and stipsan committed Aug 2, 2016
1 parent 70f5b9f commit 7312f83
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"dependencies": {
"bluebird": "3.4.1",
"lodash": "4.14.1",
"minimatch": "^3.0.2",
"redis-commands": "1.2.0"
}
}
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './hstrlen';
export * from './hvals';
export * from './incr';
export * from './incrby';
export * from './keys';
export * from './rename';
export * from './sadd';
export * from './set';
Expand Down
5 changes: 5 additions & 0 deletions src/commands/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import minimatch from 'minimatch';

export function keys(globString) {
return Object.keys(this.data).filter((key) => minimatch(key, globString));
}
34 changes: 34 additions & 0 deletions test/commands/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import expect from 'expect';

import MockRedis from '../../src';

describe('keys', () => {
it('should return an empty array if there are no keys', () => {
const redis = new MockRedis();

return redis.keys('*').then(result => expect(result).toEqual([]));
});

it('should return all data keys', () => {
const redis = new MockRedis({
data: {
foo: 'bar',
baz: 'quux',
},
});

return redis.keys('*').then(result => expect(result).toEqual(['foo', 'baz']));
});

it('should only return keys matching the given pattern', () => {
const redis = new MockRedis({
data: {
foo: 'bar',
baz: 'quux',
flambé: 'baked alaska',
},
});

return redis.keys('f*').then(result => expect(result).toEqual(['foo', 'flambé']));
});
});

0 comments on commit 7312f83

Please sign in to comment.