1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

fix returnBuffers, add some tests

This commit is contained in:
leibale
2021-12-29 17:09:59 -05:00
parent 74daee3023
commit 77022209bd
11 changed files with 149 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './LOADCHUNK';
describe('BF LOADCHUNK', () => {
@@ -8,4 +9,20 @@ describe('BF LOADCHUNK', () => {
['BF.LOADCHUNK', 'key', '0', '']
);
});
testUtils.testWithClient('client.bf.loadChunk', async client => {
const [, { iterator, chunk }] = await Promise.all([
client.bf.reserve('source', 0.01, 100),
client.bf.scanDump(
client.commandOptions({ returnBuffers: true }),
'source',
0
)
]);
assert.equal(
await client.bf.loadChunk('destination', iterator, chunk),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,4 +1,5 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './SCANDUMP';
describe('BF SCANDUMP', () => {
@@ -8,4 +9,14 @@ describe('BF SCANDUMP', () => {
['BF.SCANDUMP', 'key', '0']
);
});
testUtils.testWithClient('client.bf.scanDump', async client => {
const [, dump] = await Promise.all([
client.bf.reserve('key', 0.01, 100),
client.bf.scanDump('key', 0)
]);
assert.equal(typeof dump, 'object');
assert.equal(typeof dump.iterator, 'number');
assert.equal(typeof dump.chunk, 'string');
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,4 +1,5 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './LOADCHUNK';
describe('CF LOADCHUNK', () => {
@@ -8,4 +9,23 @@ describe('CF LOADCHUNK', () => {
['CF.LOADCHUNK', 'item', '0', '']
);
});
testUtils.testWithClient('client.cf.loadChunk', async client => {
const [,, { iterator, chunk }] = await Promise.all([
client.cf.reserve('source', 4),
client.cf.add('source', 'item'),
client.cf.scanDump(
client.commandOptions({ returnBuffers: true }),
'source',
0
)
]);
assert.ok(Buffer.isBuffer(chunk));
assert.equal(
await client.cf.loadChunk('destination', iterator, chunk),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,6 +1,12 @@
import { RedisCommandArgument, RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, iterator: number, chunk: string): Array<string> {
export function transformArguments(
key: string,
iterator: number,
chunk: RedisCommandArgument
): RedisCommandArguments {
return ['CF.LOADCHUNK', key, iterator.toString(), chunk];
}

View File

@@ -1,4 +1,5 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../../test-utils';
import { transformArguments } from './SCANDUMP';
describe('CF SCANDUMP', () => {
@@ -8,4 +9,15 @@ describe('CF SCANDUMP', () => {
['CF.SCANDUMP', 'key', '0']
);
});
testUtils.testWithClient('client.cf.scanDump', async client => {
await client.cf.reserve('key', 4);
assert.deepEqual(
await client.cf.scanDump('key', 0),
{
iterator: 0,
chunk: null
}
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -6,12 +6,12 @@ export function transformArguments(key: string, iterator: number): Array<string>
type ScanDumpRawReply = [
iterator: number,
chunk: string
chunk: string | null
];
interface ScanDumpReply {
iterator: number;
chunk: string;
chunk: string | null;
}
export function transformReply([iterator, chunk]: ScanDumpRawReply): ScanDumpReply {