Skip to content

Commit

Permalink
feat: add sinterBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 31, 2022
1 parent 21840a3 commit 2bad9d6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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: 60%](https://img.shields.io/badge/redis-60%25-orange.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: 61%](https://img.shields.io/badge/redis-61%25-orange.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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Supported commands ![Commands Coverage: 60%](https://img.shields.io/badge/coverage-60%25-orange.svg)
## Supported commands ![Commands Coverage: 61%](https://img.shields.io/badge/coverage-61%25-orange.svg)

> PRs welcome :heart:
Expand Down Expand Up @@ -218,7 +218,6 @@

- [hscanBuffer][1]
- [scanBuffer][1]
- [sinterBuffer][1]
- [smembersBuffer][1]
- [spopBuffer][1]
- [srandmemberBuffer][1]
Expand Down
5 changes: 5 additions & 0 deletions src/commands/sinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export function sinter(...keys) {

return Array.from(intersection)
}

export function sinterBuffer(...args) {
const val = sinter.apply(this, args)
return val.map(Buffer.from)
}
63 changes: 37 additions & 26 deletions test/integration/commands/sinter.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
import Redis from 'ioredis'

describe('sinter', () => {
it('should return the members from the intersection of all the given sets', () => {
const redis = new Redis({
data: {
key1: new Set(['a', 'b', 'c', 'd']),
key2: new Set(['c']),
key3: new Set(['a', 'c', 'e']),
},
})
// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

return redis.sinter('key1', 'key2', 'key3').then(result => {
return expect(result).toEqual(['c'])
})
})
runTwinSuite('sinter', command => {
describe(command, () => {
it('should return the members from the intersection of all the given sets', () => {
const redis = new Redis({
data: {
key1: new Set(['a', 'b', 'c', 'd']),
key2: new Set(['c']),
key3: new Set(['a', 'c', 'e']),
},
})

it('should throw an exception if one of the keys is not a set', () => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
return redis[command]('key1', 'key2', 'key3').then(result => {
return expect(
command === 'sinterBuffer'
? result.map(v => {
return v.toString()
})
: result
).toEqual(['c'])
})
})

return redis.sinter('foo', 'bar').catch(err => {
return expect(err.message).toBe('Key bar does not contain a set')
it('should throw an exception if one of the keys is not a set', () => {
const redis = new Redis({
data: {
foo: new Set(),
bar: 'not a set',
},
})

return redis[command]('foo', 'bar').catch(err => {
return expect(err.message).toBe('Key bar does not contain a set')
})
})
})

it("should return empty array if sources don't exists", () => {
const redis = new Redis()
it("should return empty array if sources don't exists", () => {
const redis = new Redis()

return redis.sinter('foo', 'bar').then(result => {
return expect(result).toEqual([])
return redis[command]('foo', 'bar').then(result => {
return expect(result).toEqual([])
})
})
})
})

0 comments on commit 2bad9d6

Please sign in to comment.