Skip to content

HSCAN NOVALUES support (v5) #2758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/client/lib/commands/HSCAN_VALUES.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HSCAN_VALUES from './HSCAN_VALUES';

describe('HSCAN_VALUES', () => {
describe('transformArguments', () => {
it('cusror only', () => {
assert.deepEqual(
HSCAN_VALUES.transformArguments('key', '0'),
['HSCAN', 'key', '0', 'VALUES']
);
});

it('with MATCH', () => {
assert.deepEqual(
HSCAN_VALUES.transformArguments('key', '0', {
MATCH: 'pattern'
}),
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'VALUES']
);
});

it('with COUNT', () => {
assert.deepEqual(
HSCAN_VALUES.transformArguments('key', '0', {
COUNT: 1
}),
['HSCAN', 'key', '0', 'COUNT', '1', 'VALUES']
);
});

it('with MATCH & COUNT', () => {
assert.deepEqual(
HSCAN_VALUES.transformArguments('key', '0', {
MATCH: 'pattern',
COUNT: 1
}),
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'COUNT', '1', 'VALUES']
);
});
});

testUtils.testWithClient('client.hScanValues', async client => {
const [, reply] = await Promise.all([
client.hSet('key', 'field', 'value'),
client.hScanValues('key', '0')
]);

assert.deepEqual(reply, {
cursor: '0',
entries: [
'field',
]
});
}, GLOBAL.SERVERS.OPEN);
});
18 changes: 18 additions & 0 deletions packages/client/lib/commands/HSCAN_VALUES.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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('VALUES');

return args;
},
transformReply: undefined as unknown as () => [BlobStringReply, Array<BlobStringReply>]
} as const satisfies Command;
3 changes: 3 additions & 0 deletions packages/client/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import HRANDFIELD_COUNT_WITHVALUES from './HRANDFIELD_COUNT_WITHVALUES';
import HRANDFIELD_COUNT from './HRANDFIELD_COUNT';
import HRANDFIELD from './HRANDFIELD';
import HSCAN from './HSCAN';
import HSCAN_VALUES from './HSCAN_VALUES';
import HSET from './HSET';
import HSETNX from './HSETNX';
import HSTRLEN from './HSTRLEN';
Expand Down Expand Up @@ -623,6 +624,8 @@ export default {
hRandField: HRANDFIELD,
HSCAN,
hScan: HSCAN,
HSCAN_VALUES,
hScanValues: HSCAN_VALUES,
HSET,
hSet: HSET,
HSETNX,
Expand Down