-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Redis.SMISMEMBER support (#1100)
- Loading branch information
Showing
4 changed files
with
34 additions
and
1 deletion.
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 |
---|---|---|
@@ -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); | ||
} |
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 |
---|---|---|
@@ -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])); | ||
}); | ||
}); |