forked from stipsan/ioredis-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added badge to compat table for easy overview * fix messed up render * add title * add getrange command
- Loading branch information
Showing
5 changed files
with
73 additions
and
10 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
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,9 @@ | ||
export function getrange(key, start, end) { | ||
const val = this.data.get(key); | ||
|
||
if (end === -1) { | ||
return val.slice(start); | ||
} | ||
|
||
return val.slice(start, end + 1); | ||
} |
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,27 @@ | ||
import expect from 'expect'; | ||
|
||
import MockRedis from '../../src'; | ||
|
||
describe('getrange', () => { | ||
const redis = new MockRedis({ | ||
data: { | ||
foo: 'This is a string', | ||
}, | ||
}); | ||
|
||
it('should return "This"', () => | ||
redis.getrange('foo', 0, 3).then(result => expect(result).toBe('This')) | ||
); | ||
|
||
it('should return "ing"', () => | ||
redis.getrange('foo', -3, -1).then(result => expect(result).toBe('ing')) | ||
); | ||
|
||
it('should return "This is a string"', () => | ||
redis.getrange('foo', 0, -1).then(result => expect(result).toBe('This is a string')) | ||
); | ||
|
||
it('should return "string"', () => | ||
redis.getrange('foo', 10, 100).then(result => expect(result).toBe('string')) | ||
); | ||
}); |