You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fix(commands): sPopCount return Array<string> (#3006)
Also, touch the tests for spop and spopcount to use the new parseCommand API fixes #3004
This commit is contained in:
committed by
GitHub
parent
c5b4f47975
commit
742d5713e8
@@ -1,12 +1,14 @@
|
|||||||
import { strict as assert } from 'node:assert';
|
import { strict as assert } from 'node:assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import SPOP from './SPOP';
|
import SPOP from './SPOP';
|
||||||
import { parseArgs } from './generic-transformers';
|
import { BasicCommandParser } from '../client/parser';
|
||||||
|
|
||||||
describe('SPOP', () => {
|
describe('SPOP', () => {
|
||||||
it('transformArguments', () => {
|
it('transformArguments', () => {
|
||||||
|
const parser = new BasicCommandParser();
|
||||||
|
SPOP.parseCommand(parser, 'key');
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
parseArgs(SPOP, 'key'),
|
parser.redisArgs,
|
||||||
['SPOP', 'key']
|
['SPOP', 'key']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -16,6 +18,19 @@ describe('SPOP', () => {
|
|||||||
await client.sPop('key'),
|
await client.sPop('key'),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await client.sAdd('key', 'member');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await client.sPop('key'),
|
||||||
|
'member'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await client.sPop('key'),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
client: GLOBAL.SERVERS.OPEN,
|
client: GLOBAL.SERVERS.OPEN,
|
||||||
cluster: GLOBAL.CLUSTERS.OPEN
|
cluster: GLOBAL.CLUSTERS.OPEN
|
||||||
|
@@ -1,21 +1,36 @@
|
|||||||
import { strict as assert } from 'node:assert';
|
import { strict as assert } from 'node:assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import SPOP_COUNT from './SPOP_COUNT';
|
import SPOP_COUNT from './SPOP_COUNT';
|
||||||
import { parseArgs } from './generic-transformers';
|
import { BasicCommandParser } from '../client/parser';
|
||||||
|
|
||||||
describe('SPOP_COUNT', () => {
|
describe('SPOP_COUNT', () => {
|
||||||
it('transformArguments', () => {
|
it('transformArguments', () => {
|
||||||
|
const parser = new BasicCommandParser();
|
||||||
|
SPOP_COUNT.parseCommand(parser, 'key', 1);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
parseArgs(SPOP_COUNT, 'key', 1),
|
parser.redisArgs,
|
||||||
['SPOP', 'key', '1']
|
['SPOP', 'key', '1']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testAll('sPopCount', async client => {
|
testUtils.testAll('sPopCount', async client => {
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.sPopCount('key', 1),
|
await client.sPopCount('key', 1),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
client.sAdd('key', 'member'),
|
||||||
|
client.sAdd('key', 'member2'),
|
||||||
|
client.sAdd('key', 'member3')
|
||||||
|
])
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
(await client.sPopCount('key', 3)).length,
|
||||||
|
3
|
||||||
|
);
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
client: GLOBAL.SERVERS.OPEN,
|
client: GLOBAL.SERVERS.OPEN,
|
||||||
cluster: GLOBAL.CLUSTERS.OPEN
|
cluster: GLOBAL.CLUSTERS.OPEN
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { CommandParser } from '../client/parser';
|
import { CommandParser } from '../client/parser';
|
||||||
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
import { RedisArgument, Command, ArrayReply } from '../RESP/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
@@ -16,5 +16,5 @@ export default {
|
|||||||
parser.pushKey(key);
|
parser.pushKey(key);
|
||||||
parser.push(count.toString());
|
parser.push(count.toString());
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
transformReply: undefined as unknown as () => ArrayReply<string>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
Reference in New Issue
Block a user