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
6 changed files
with
28 additions
and
26 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
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,8 @@ | ||
export function mget(...keys) { | ||
return keys.map(key => (this.data.has(key) ? this.data.get(key) : null)) | ||
} | ||
|
||
export function mgetBuffer(...args) { | ||
const val = mget.apply(this, args) | ||
return val.map(payload => (payload ? Buffer.from(payload) : payload)) | ||
} |
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,28 @@ | ||
import Redis from 'ioredis' | ||
|
||
describe('mget', () => { | ||
it('should return null 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.mget('foo').then(result => { | ||
return expect(result).toEqual([null]) | ||
}) | ||
}) | ||
runTwinSuite('mget', (command, equals) => { | ||
describe(command, () => { | ||
it('should return null on keys that do not exist', async () => { | ||
const redis = new Redis() | ||
|
||
const result = await redis[command]('foo') | ||
expect(result[0]).toBe(null) | ||
|
||
it('should return value keys that exist', () => { | ||
const redis = new Redis({ | ||
data: { | ||
foo: 'bar', | ||
}, | ||
redis.disconnect() | ||
}) | ||
|
||
return redis.mget('foo', 'hello').then(result => { | ||
return expect(result).toEqual(['bar', null]) | ||
it('should return value keys that exist', async () => { | ||
const redis = new Redis() | ||
await redis.set('foo', 'bar') | ||
|
||
const result = await redis[command]('foo', 'hello') | ||
expect(equals(result[0], 'bar')).toBe(true) | ||
expect(result[1]).toBe(null) | ||
|
||
redis.disconnect() | ||
}) | ||
}) | ||
}) |