Skip to content

Commit

Permalink
feat: Redis.SMISMEMBER support (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
venku122 authored Nov 4, 2021
1 parent 8b93033 commit d553b86
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
| [slaveof] | :white_check_mark: | :x: | [slaveofBuffer][1] | :white_check_mark: | :x: |
| [slowlog] | :white_check_mark: | :x: | [slowlogBuffer][1] | :white_check_mark: | :x: |
| [smembers] | :white_check_mark: | :white_check_mark: | [smembersBuffer][1] | :white_check_mark: | :x: |
| [smismember] | :white_check_mark: | :x: | [smismemberBuffer][1] | :white_check_mark: | :x: |
| [smismember] | :white_check_mark: | :white_check_mark: | [smismemberBuffer][1] | :white_check_mark: | :x: |
| [smove] | :white_check_mark: | :white_check_mark: | [smoveBuffer][1] | :white_check_mark: | :x: |
| [sort] | :white_check_mark: | :x: | [sortBuffer][1] | :white_check_mark: | :x: |
| [spop] | :white_check_mark: | :white_check_mark: | [spopBuffer][1] | :white_check_mark: | :x: |
Expand Down
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export * from './setnx';
export * from './sinter';
export * from './sinterstore';
export * from './sismember';
export * from './smismember';
export * from './smembers';
export * from './smove';
export * from './spop';
Expand Down
8 changes: 8 additions & 0 deletions src/commands/smismember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function smismember(key, ...valArray) {
const data = this.data.get(key);

if (data) {
return valArray.map((val) => data.has(val) ? 1 : 0);
}
return valArray.map(() => 0);
}
24 changes: 24 additions & 0 deletions test/commands/smismember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Redis from 'ioredis';

describe('smismember', () => {
it('should check if each item exists in set', async () => {
const valuesInTheSet = ['foo', 'bar'];
const redis = new Redis({
data: {
setKey: new Set(valuesInTheSet),
},
});

// should take n number of values after the key
const result = await redis.smismember('setKey', ...valuesInTheSet);
expect(result).toEqual(expect.arrayContaining([1, 1]));

// should take a single value as well but return an array
const result2 = await redis.smismember('foos', 'foobar');
expect(result2).toEqual(expect.arrayContaining([0]));

// should return 0 if a value is not included in the set
const result3 = await redis.smismember('setKey', ...['foobar', ...valuesInTheSet]);
expect(result3).toEqual(expect.arrayContaining([0, 1, 1]));
});
});

0 comments on commit d553b86

Please sign in to comment.