Skip to content

Commit

Permalink
feat: add mgetBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 30, 2022
1 parent 11bbf35 commit 76e0550
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# ioredis-mock · [![npm](https://img.shields.io/npm/dm/ioredis-mock.svg?style=flat-square)](https://npm-stat.com/charts.html?package=ioredis-mock) [![npm version](https://img.shields.io/npm/v/ioredis-mock.svg?style=flat-square)](https://www.npmjs.com/package/ioredis-mock) [![Redis Compatibility: 42%](https://img.shields.io/badge/redis-42%25-red.svg?style=flat-square)](compat.md) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
# ioredis-mock · [![npm](https://img.shields.io/npm/dm/ioredis-mock.svg?style=flat-square)](https://npm-stat.com/charts.html?package=ioredis-mock) [![npm version](https://img.shields.io/npm/v/ioredis-mock.svg?style=flat-square)](https://www.npmjs.com/package/ioredis-mock) [![Redis Compatibility: 43%](https://img.shields.io/badge/redis-43%25-red.svg?style=flat-square)](compat.md) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)

This library emulates [ioredis](https://github.com/luin/ioredis) by performing
all operations in-memory. The best way to do integration testing against redis
Expand Down
3 changes: 1 addition & 2 deletions compat.md
@@ -1,4 +1,4 @@
## Supported commands ![Commands Coverage: 42%](https://img.shields.io/badge/coverage-42%25-red.svg)
## Supported commands ![Commands Coverage: 43%](https://img.shields.io/badge/coverage-43%25-red.svg)

| redis | ioredis | ioredis-mock |
| ---------------------- | :----------------: | :----------------: |
Expand Down Expand Up @@ -232,7 +232,6 @@
- [lremBuffer][1]
- [lsetBuffer][1]
- [ltrimBuffer][1]
- [mgetBuffer][1]
- [persistBuffer][1]
- [pexpireBuffer][1]
- [pexpireatBuffer][1]
Expand Down
7 changes: 0 additions & 7 deletions jest.config.redis.js
Expand Up @@ -18,13 +18,10 @@ module.exports = {
'test/integration/commands/hexists.js',
'test/integration/commands/hget.js',
'test/integration/commands/hgetall.js',
'test/integration/commands/hgetallBuffer.js',
'test/integration/commands/hgetBuffer.js',
'test/integration/commands/hincrby.js',
'test/integration/commands/hincrbyfloat.js',
'test/integration/commands/hlen.js',
'test/integration/commands/hmget.js',
'test/integration/commands/hmgetBuffer.js',
'test/integration/commands/hscan.js',
'test/integration/commands/hscanStream.js',
'test/integration/commands/hstrlen.js',
Expand All @@ -35,14 +32,12 @@ module.exports = {
'test/integration/commands/linsert.js',
'test/integration/commands/llen.js',
'test/integration/commands/lpop.js',
'test/integration/commands/lpopBuffer.js',
'test/integration/commands/lpush.js',
'test/integration/commands/lpushx.js',
'test/integration/commands/lrange.js',
'test/integration/commands/lrem.js',
'test/integration/commands/lset.js',
'test/integration/commands/ltrim.js',
'test/integration/commands/mget.js',
'test/integration/commands/persist.js',
'test/integration/commands/pexpire.js',
'test/integration/commands/pexpireat.js',
Expand All @@ -53,9 +48,7 @@ module.exports = {
'test/integration/commands/renamenx.js',
'test/integration/commands/role.js',
'test/integration/commands/rpop.js',
'test/integration/commands/rpopBuffer.js',
'test/integration/commands/rpoplpush.js',
'test/integration/commands/rpoplpushBuffer.js',
'test/integration/commands/rpush.js',
'test/integration/commands/rpushx.js',
'test/integration/commands/scan.js',
Expand Down
4 changes: 2 additions & 2 deletions src/commands/hmget.js
Expand Up @@ -8,7 +8,7 @@ export function hmget(key, ...fields) {
})
}

export function hmgetBuffer(key, ...fields) {
const val = hmget.apply(this, [key, ...fields])
export function hmgetBuffer(...args) {
const val = hmget.apply(this, args)
return val.map(payload => (payload ? Buffer.from(payload) : payload))
}
5 changes: 5 additions & 0 deletions src/commands/mget.js
@@ -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))
}
33 changes: 19 additions & 14 deletions test/integration/commands/mget.js
@@ -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()
})
})
})

0 comments on commit 76e0550

Please sign in to comment.