Skip to content

Commit 742d571

Browse files
authored
fix(commands): sPopCount return Array<string> (#3006)
Also, touch the tests for spop and spopcount to use the new parseCommand API fixes #3004
1 parent c5b4f47 commit 742d571

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

packages/client/lib/commands/SPOP.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
import SPOP from './SPOP';
4-
import { parseArgs } from './generic-transformers';
4+
import { BasicCommandParser } from '../client/parser';
55

66
describe('SPOP', () => {
77
it('transformArguments', () => {
8+
const parser = new BasicCommandParser();
9+
SPOP.parseCommand(parser, 'key');
810
assert.deepEqual(
9-
parseArgs(SPOP, 'key'),
11+
parser.redisArgs,
1012
['SPOP', 'key']
1113
);
1214
});
@@ -16,6 +18,19 @@ describe('SPOP', () => {
1618
await client.sPop('key'),
1719
null
1820
);
21+
22+
await client.sAdd('key', 'member');
23+
24+
assert.equal(
25+
await client.sPop('key'),
26+
'member'
27+
);
28+
29+
assert.equal(
30+
await client.sPop('key'),
31+
null
32+
);
33+
1934
}, {
2035
client: GLOBAL.SERVERS.OPEN,
2136
cluster: GLOBAL.CLUSTERS.OPEN

packages/client/lib/commands/SPOP_COUNT.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
import SPOP_COUNT from './SPOP_COUNT';
4-
import { parseArgs } from './generic-transformers';
4+
import { BasicCommandParser } from '../client/parser';
55

66
describe('SPOP_COUNT', () => {
77
it('transformArguments', () => {
8+
const parser = new BasicCommandParser();
9+
SPOP_COUNT.parseCommand(parser, 'key', 1);
810
assert.deepEqual(
9-
parseArgs(SPOP_COUNT, 'key', 1),
11+
parser.redisArgs,
1012
['SPOP', 'key', '1']
1113
);
1214
});
1315

1416
testUtils.testAll('sPopCount', async client => {
17+
1518
assert.deepEqual(
1619
await client.sPopCount('key', 1),
1720
[]
1821
);
22+
23+
await Promise.all([
24+
client.sAdd('key', 'member'),
25+
client.sAdd('key', 'member2'),
26+
client.sAdd('key', 'member3')
27+
])
28+
29+
assert.deepEqual(
30+
(await client.sPopCount('key', 3)).length,
31+
3
32+
);
33+
1934
}, {
2035
client: GLOBAL.SERVERS.OPEN,
2136
cluster: GLOBAL.CLUSTERS.OPEN

packages/client/lib/commands/SPOP_COUNT.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommandParser } from '../client/parser';
2-
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
2+
import { RedisArgument, Command, ArrayReply } from '../RESP/types';
33

44
export default {
55
IS_READ_ONLY: false,
@@ -16,5 +16,5 @@ export default {
1616
parser.pushKey(key);
1717
parser.push(count.toString());
1818
},
19-
transformReply: undefined as unknown as () => BlobStringReply | NullReply
19+
transformReply: undefined as unknown as () => ArrayReply<string>
2020
} as const satisfies Command;

0 commit comments

Comments
 (0)