Skip to content

HSCAN VALUES support (v4) #2759

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions packages/client/lib/cluster/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import * as HRANDFIELD_COUNT_WITHVALUES from '../commands/HRANDFIELD_COUNT_WITHV
import * as HRANDFIELD_COUNT from '../commands/HRANDFIELD_COUNT';
import * as HRANDFIELD from '../commands/HRANDFIELD';
import * as HSCAN from '../commands/HSCAN';
import * as HSCAN_VALUES from '../commands/HSCAN_VALUES';
import * as HSET from '../commands/HSET';
import * as HSETNX from '../commands/HSETNX';
import * as HSTRLEN from '../commands/HSTRLEN';
Expand Down Expand Up @@ -343,6 +344,8 @@ export default {
hRandField: HRANDFIELD,
HSCAN,
hScan: HSCAN,
HSCAN_VALUES,
hScanValues: HSCAN_VALUES,
HSET,
hSet: HSET,
HSETNX,
Expand Down
76 changes: 76 additions & 0 deletions packages/client/lib/commands/HSCAN_VALUES.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './HSCAN_VALUES';

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

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

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

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

describe('transformReply', () => {
it('without tuples', () => {
assert.deepEqual(
transformReply(['0', []]),
{
cursor: 0,
fields: []
}
);
});

it('with tuples', () => {
assert.deepEqual(
transformReply(['0', ['field']]),
{
cursor: 0,
fields: [
'field',
]
}
);
});
});

testUtils.testWithClient('client.hScan', async client => {
assert.deepEqual(
await client.hScanValues('key', 0),
{
cursor: 0,
fields: []
}
);
}, GLOBAL.SERVERS.OPEN);
});
39 changes: 39 additions & 0 deletions packages/client/lib/commands/HSCAN_VALUES.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { RedisCommandArgument, RedisCommandArguments } from '.';
import { ScanOptions, pushScanArguments } from './generic-transformers';

export const FIRST_KEY_INDEX = 1;

export const IS_READ_ONLY = true;

export function transformArguments(
key: RedisCommandArgument,
cursor: number,
options?: ScanOptions
): RedisCommandArguments {
const args = pushScanArguments([
'HSCAN',
key
], cursor, options);
args.push('VALUES');

return args;
}

type HScanRawReply = [RedisCommandArgument, Array<RedisCommandArgument>];

export interface HScanTuple {
field: RedisCommandArgument;
value: RedisCommandArgument;
}

interface HScanValueReply {
cursor: number;
fields: Array<RedisCommandArgument>;
}

export function transformReply([cursor, fields]: HScanRawReply): HScanValueReply {
return {
cursor: Number(cursor),
fields: fields
};
}
Loading