You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
V5 bringing RESP3, Sentinel and TypeMapping to node-redis
RESP3 Support - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion. Sentinel TypeMapping Correctly types Multi commands Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
@@ -1,79 +1,82 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments, transformReply } from './HSCAN_NOVALUES';
|
||||
import HSCAN_NOVALUES from './HSCAN_NOVALUES';
|
||||
import { BlobStringReply } from '../RESP/types';
|
||||
|
||||
describe('HSCAN_NOVALUES', () => {
|
||||
testUtils.isVersionGreaterThanHook([7, 4]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('cusror only', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 0),
|
||||
['HSCAN', 'key', '0', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
|
||||
it('with MATCH', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 0, {
|
||||
MATCH: 'pattern'
|
||||
}),
|
||||
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
|
||||
it('with COUNT', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 0, {
|
||||
COUNT: 1
|
||||
}),
|
||||
['HSCAN', 'key', '0', 'COUNT', '1', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
testUtils.isVersionGreaterThanHook([7,4]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('cusror only', () => {
|
||||
assert.deepEqual(
|
||||
HSCAN_NOVALUES.transformArguments('key', '0'),
|
||||
['HSCAN', 'key', '0', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
|
||||
describe('transformReply', () => {
|
||||
it('without keys', () => {
|
||||
assert.deepEqual(
|
||||
transformReply(['0', []]),
|
||||
{
|
||||
cursor: 0,
|
||||
keys: []
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('with keys', () => {
|
||||
assert.deepEqual(
|
||||
transformReply(['0', ['key1', 'key2']]),
|
||||
{
|
||||
cursor: 0,
|
||||
keys: ['key1', 'key2']
|
||||
}
|
||||
);
|
||||
});
|
||||
it('with MATCH', () => {
|
||||
assert.deepEqual(
|
||||
HSCAN_NOVALUES.transformArguments('key', '0', {
|
||||
MATCH: 'pattern'
|
||||
}),
|
||||
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.hScanNoValues', async client => {
|
||||
assert.deepEqual(
|
||||
await client.hScanNoValues('key', 0),
|
||||
{
|
||||
cursor: 0,
|
||||
keys: []
|
||||
}
|
||||
);
|
||||
it('with COUNT', () => {
|
||||
assert.deepEqual(
|
||||
HSCAN_NOVALUES.transformArguments('key', '0', {
|
||||
COUNT: 1
|
||||
}),
|
||||
['HSCAN', 'key', '0', 'COUNT', '1', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
client.hSet('key', 'a', '1'),
|
||||
client.hSet('key', 'b', '2')
|
||||
]);
|
||||
it('with MATCH & COUNT', () => {
|
||||
assert.deepEqual(
|
||||
HSCAN_NOVALUES.transformArguments('key', '0', {
|
||||
MATCH: 'pattern',
|
||||
COUNT: 1
|
||||
}),
|
||||
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'COUNT', '1', 'NOVALUES']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
await client.hScanNoValues('key', 0),
|
||||
{
|
||||
cursor: 0,
|
||||
keys: ['a', 'b']
|
||||
}
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
describe('transformReply', () => {
|
||||
it('without keys', () => {
|
||||
assert.deepEqual(
|
||||
HSCAN_NOVALUES.transformReply(['0' as any, []]),
|
||||
{
|
||||
cursor: '0',
|
||||
fields: []
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('with keys', () => {
|
||||
assert.deepEqual(
|
||||
HSCAN_NOVALUES.transformReply(['0' as any, ['key1', 'key2'] as any]),
|
||||
{
|
||||
cursor: '0',
|
||||
fields: ['key1', 'key2']
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
testUtils.testWithClient('client.hScanNoValues', async client => {
|
||||
const [, reply] = await Promise.all([
|
||||
client.hSet('key', 'field', 'value'),
|
||||
client.hScanNoValues('key', '0')
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, {
|
||||
cursor: '0',
|
||||
fields: [
|
||||
'field',
|
||||
]
|
||||
});
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
Reference in New Issue
Block a user