Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
22 additions
and
16 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export function strlen(key) { | ||
return this.data.has(key) ? this.data.get(key).length : 0 | ||
} | ||
|
||
export const strlenBuffer = strlen |
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 |
---|---|---|
@@ -1,23 +1,29 @@ | ||
import Redis from 'ioredis' | ||
|
||
describe('strlen', () => { | ||
it('should return 0 on keys that do not exist', () => { | ||
const redis = new Redis() | ||
// eslint-disable-next-line import/no-relative-parent-imports | ||
import { runTwinSuite } from '../../../test-utils' | ||
|
||
return redis.strlen('nonexisting').then(result => { | ||
return expect(result).toBe(0) | ||
}) | ||
}) | ||
runTwinSuite('strlen', command => { | ||
describe(command, () => { | ||
it('should return 0 on keys that do not exist', async () => { | ||
const redis = new Redis() | ||
|
||
expect(await redis[command]('nonexisting')).toBe(0) | ||
|
||
it('should return string length of keys that do exist', () => { | ||
const redis = new Redis({ | ||
data: { | ||
mykey: 'Hello world', | ||
}, | ||
redis.disconnect() | ||
}) | ||
|
||
return redis.strlen('mykey').then(result => { | ||
return expect(result).toBe(11) | ||
it('should return string length of keys that do exist', async () => { | ||
const redis = new Redis({ | ||
data: { | ||
mykey: 'Hello world', | ||
}, | ||
}) | ||
await redis.set('mykey', 'Hello world') | ||
|
||
expect(await redis[command]('mykey')).toBe(11) | ||
|
||
redis.disconnect() | ||
}) | ||
}) | ||
}) |