Skip to content

Commit

Permalink
fix: srandmember with count argument should return array of strings (#…
Browse files Browse the repository at this point in the history
…1620)


Co-authored-by: Zihua Li <i@zihua.li>
  • Loading branch information
joni7777 and luin committed Jul 23, 2022
1 parent d8a87bc commit 5f813f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bin/returnTypes.js
Expand Up @@ -265,7 +265,7 @@ module.exports = {
sort: "number" | "unknown[]",
sortRo: "unknown[]",
spop: (types) => (types.length > 1 ? "string[]" : "string | null"),
srandmember: "string | unknown[] | null",
srandmember: (types) => (types.length > 1 ? "string[]" : "string | null"),
srem: "number",
strlen: "number",
sunion: "string[]",
Expand Down
16 changes: 8 additions & 8 deletions lib/utils/RedisCommander.ts
Expand Up @@ -8139,22 +8139,22 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
*/
srandmember(
key: RedisKey,
callback?: Callback<string | unknown[] | null>
): Result<string | unknown[] | null, Context>;
callback?: Callback<string | null>
): Result<string | null, Context>;
srandmemberBuffer(
key: RedisKey,
callback?: Callback<Buffer | unknown[] | null>
): Result<Buffer | unknown[] | null, Context>;
callback?: Callback<Buffer | null>
): Result<Buffer | null, Context>;
srandmember(
key: RedisKey,
count: number | string,
callback?: Callback<string | unknown[] | null>
): Result<string | unknown[] | null, Context>;
callback?: Callback<string[]>
): Result<string[], Context>;
srandmemberBuffer(
key: RedisKey,
count: number | string,
callback?: Callback<Buffer | unknown[] | null>
): Result<Buffer | unknown[] | null, Context>;
callback?: Callback<Buffer[]>
): Result<Buffer[], Context>;

/**
* Remove one or more members from a set
Expand Down
6 changes: 6 additions & 0 deletions test/typing/commands.test-d.ts
Expand Up @@ -71,6 +71,12 @@ expectType<Promise<number[]>>(
redis.lpos("key", "element", "RANK", -1, "COUNT", 2)
);

// SRANDMEMBER
expectType<Promise<string | null>>(redis.srandmember("key"));
expectType<Promise<Buffer | null>>(redis.srandmemberBuffer("key"));
expectType<Promise<string[]>>(redis.srandmember("key", 10));
expectType<Promise<Buffer[]>>(redis.srandmemberBuffer("key", 10));

// LMISMEMBER
expectType<Promise<number[]>>(redis.smismember("key", "e1", "e2"));

Expand Down

0 comments on commit 5f813f3

Please sign in to comment.