diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bcf55d700..3f961323b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ * Python Node: Allow routing Cluster requests by address. ([#1021](https://github.com/aws/glide-for-redis/pull/1021)) * Python: Added HSETNX command. ([#954](https://github.com/aws/glide-for-redis/pull/954)) -* Python: Added SISMEMBER command ([#971](https://github.com/aws/glide-for-redis/pull/971)) +* Python, Node: Added SISMEMBER command ([#972](https://github.com/aws/glide-for-redis/pull/972), [#1083](https://github.com/aws/glide-for-redis/pull/1083)) * Python, Node: Added TYPE command ([#945](https://github.com/aws/glide-for-redis/pull/945), [#980](https://github.com/aws/glide-for-redis/pull/980)) * Python, Node: Added HLEN command ([#944](https://github.com/aws/glide-for-redis/pull/944), [#981](https://github.com/aws/glide-for-redis/pull/981)) * Python, Node: Added ZCOUNT command ([#878](https://github.com/aws/glide-for-redis/pull/878)) ([#909](https://github.com/aws/glide-for-redis/pull/909)) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index ae9363b0d2..64d5cf18fd 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -56,6 +56,7 @@ import { createSMembers, createSRem, createSet, + createSismember, createStrlen, createTTL, createType, @@ -827,6 +828,18 @@ export class BaseClient { return this.createWritePromise(createSCard(key)); } + /** Returns if `member` is a member of the set stored at `key`. + * See https://redis.io/commands/sismember/ for more details. + * + * @param key - The key of the set. + * @param member - The member to check for existence in the set. + * @returns `true` if the member exists in the set, `false` otherwise. + * If `key` doesn't exist, it is treated as an empty set and the command returns `false`. + */ + public sismember(key: string, member: string): Promise { + return this.createWritePromise(createSismember(key, member)); + } + /** Returns the number of keys in `keys` that exist in the database. * See https://redis.io/commands/exists/ for details. * diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 15e2cd50df..27d47f7e9d 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -545,6 +545,16 @@ export function createSCard(key: string): redis_request.Command { return createCommand(RequestType.SCard, [key]); } +/** + * @internal + */ +export function createSismember( + key: string, + member: string, +): redis_request.Command { + return createCommand(RequestType.SIsMember, [key, member]); +} + /** * @internal */ diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index f343b9bee1..72d371d09b 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -59,6 +59,7 @@ import { createSRem, createSelect, createSet, + createSismember, createStrlen, createTTL, createType, @@ -636,6 +637,19 @@ export class BaseTransaction> { return this.addAndReturn(createSCard(key)); } + /** Returns if `member` is a member of the set stored at `key`. + * See https://redis.io/commands/sismember/ for more details. + * + * @param key - The key of the set. + * @param member - The member to check for existence in the set. + * + * Command Response - `true` if the member exists in the set, `false` otherwise. + * If `key` doesn't exist, it is treated as an empty set and the command returns `false`. + */ + public sismember(key: string, member: string): T { + return this.addAndReturn(createSismember(key, member)); + } + /** Returns the number of keys in `keys` that exist in the database. * See https://redis.io/commands/exists/ for details. * diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 63ee8d6503..eb42e65b95 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -1071,6 +1071,30 @@ export function runBaseTests(config: { config.timeout, ); + it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( + `sismember test_%p`, + async (protocol) => { + await runTest(async (client: BaseClient) => { + const key1 = uuidv4(); + const key2 = uuidv4(); + expect(await client.sadd(key1, ["member1"])).toEqual(1); + expect(await client.sismember(key1, "member1")).toEqual(true); + expect( + await client.sismember(key1, "nonExistingMember"), + ).toEqual(false); + expect( + await client.sismember("nonExistingKey", "member1"), + ).toEqual(false); + + expect(await client.set(key2, "foo")).toEqual("OK"); + await expect( + client.sismember(key2, "member1"), + ).rejects.toThrow(); + }, protocol); + }, + config.timeout, + ); + it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( `exists with existing keys, an non existing key_%p`, async (protocol) => { diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 43340a462b..2f4b6926ce 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -135,6 +135,8 @@ export function transactionTest( args.push(1); baseTransaction.scard(key7); args.push(1); + baseTransaction.sismember(key7, "bar"); + args.push(true); baseTransaction.smembers(key7); args.push(["bar"]); baseTransaction.zadd(key8, {