You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
HSCAN NOVALUES support (v5) (#2758)
* HSCAN VALUES support (v5) * add hscanNoValuesIterator * nitpick --------- Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
@@ -901,6 +901,19 @@ export default class RedisClient<
|
|||||||
} while (cursor !== '0');
|
} while (cursor !== '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async* hScanValuesIterator(
|
||||||
|
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
|
||||||
|
key: RedisArgument,
|
||||||
|
options?: ScanCommonOptions & ScanIteratorOptions
|
||||||
|
) {
|
||||||
|
let cursor = options?.cursor ?? '0';
|
||||||
|
do {
|
||||||
|
const reply = await this.hScanNoValues(key, cursor, options);
|
||||||
|
cursor = reply.cursor;
|
||||||
|
yield reply.fields;
|
||||||
|
} while (cursor !== '0');
|
||||||
|
}
|
||||||
|
|
||||||
async* sScanIterator(
|
async* sScanIterator(
|
||||||
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
|
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
|
||||||
key: RedisArgument,
|
key: RedisArgument,
|
||||||
|
56
packages/client/lib/commands/HSCAN_NOVALUES.spec.ts
Normal file
56
packages/client/lib/commands/HSCAN_NOVALUES.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { strict as assert } from 'node:assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import HSCAN_NOVALUES from './HSCAN_NOVALUES';
|
||||||
|
|
||||||
|
describe('HSCAN_NOVALUES', () => {
|
||||||
|
describe('transformArguments', () => {
|
||||||
|
it('cusror only', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
HSCAN_NOVALUES.transformArguments('key', '0'),
|
||||||
|
['HSCAN', 'key', '0', 'NOVALUES']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with MATCH', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
HSCAN_NOVALUES.transformArguments('key', '0', {
|
||||||
|
MATCH: 'pattern'
|
||||||
|
}),
|
||||||
|
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'NOVALUES']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with COUNT', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
HSCAN_NOVALUES.transformArguments('key', '0', {
|
||||||
|
COUNT: 1
|
||||||
|
}),
|
||||||
|
['HSCAN', 'key', '0', 'COUNT', '1', 'NOVALUES']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with MATCH & COUNT', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
HSCAN_NOVALUES.transformArguments('key', '0', {
|
||||||
|
MATCH: 'pattern',
|
||||||
|
COUNT: 1
|
||||||
|
}),
|
||||||
|
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'COUNT', '1', 'NOVALUES']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
22
packages/client/lib/commands/HSCAN_NOVALUES.ts
Normal file
22
packages/client/lib/commands/HSCAN_NOVALUES.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { RedisArgument, BlobStringReply, Command } from '../RESP/types';
|
||||||
|
import { ScanCommonOptions, pushScanArguments } from './SCAN';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
FIRST_KEY_INDEX: 1,
|
||||||
|
IS_READ_ONLY: true,
|
||||||
|
transformArguments(
|
||||||
|
key: RedisArgument,
|
||||||
|
cursor: RedisArgument,
|
||||||
|
options?: ScanCommonOptions
|
||||||
|
) {
|
||||||
|
const args = pushScanArguments(['HSCAN', key], cursor, options);
|
||||||
|
args.push('NOVALUES');
|
||||||
|
return args;
|
||||||
|
},
|
||||||
|
transformReply([cursor, fields]: [BlobStringReply, Array<BlobStringReply>]) {
|
||||||
|
return {
|
||||||
|
cursor,
|
||||||
|
fields
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} as const satisfies Command;
|
@@ -144,6 +144,7 @@ import HRANDFIELD_COUNT_WITHVALUES from './HRANDFIELD_COUNT_WITHVALUES';
|
|||||||
import HRANDFIELD_COUNT from './HRANDFIELD_COUNT';
|
import HRANDFIELD_COUNT from './HRANDFIELD_COUNT';
|
||||||
import HRANDFIELD from './HRANDFIELD';
|
import HRANDFIELD from './HRANDFIELD';
|
||||||
import HSCAN from './HSCAN';
|
import HSCAN from './HSCAN';
|
||||||
|
import HSCAN_NOVALUES from './HSCAN_NOVALUES';
|
||||||
import HSET from './HSET';
|
import HSET from './HSET';
|
||||||
import HSETNX from './HSETNX';
|
import HSETNX from './HSETNX';
|
||||||
import HSTRLEN from './HSTRLEN';
|
import HSTRLEN from './HSTRLEN';
|
||||||
@@ -623,6 +624,8 @@ export default {
|
|||||||
hRandField: HRANDFIELD,
|
hRandField: HRANDFIELD,
|
||||||
HSCAN,
|
HSCAN,
|
||||||
hScan: HSCAN,
|
hScan: HSCAN,
|
||||||
|
HSCAN_NOVALUES,
|
||||||
|
hScanNoValues: HSCAN_NOVALUES,
|
||||||
HSET,
|
HSET,
|
||||||
hSet: HSET,
|
hSet: HSET,
|
||||||
HSETNX,
|
HSETNX,
|
||||||
|
Reference in New Issue
Block a user