-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
"dependencies": { | ||
"bluebird": "3.4.1", | ||
"lodash": "4.14.1", | ||
"minimatch": "^3.0.2", | ||
"redis-commands": "1.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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é'])); | ||
}); | ||
}); |