Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Oct 14, 2024
2 parents 1f346f8 + 2fc79bd commit 1dc6d8e
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 265 deletions.
27 changes: 27 additions & 0 deletions packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,33 @@ describe('Client', () => {
assert.deepEqual(hash, results);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('hScanNoValuesIterator', async client => {
const hash: Record<string, string> = {};
const expectedFields: Array<string> = [];
for (let i = 0; i < 100; i++) {
hash[i.toString()] = i.toString();
expectedFields.push(i.toString());
}

await client.hSet('key', hash);

const actualFields: Array<string> = [];
for await (const fields of client.hScanNoValuesIterator('key')) {
for (const field of fields) {
actualFields.push(field);
}
}

function sort(a: string, b: string) {
return Number(a) - Number(b);
}

assert.deepEqual(actualFields.sort(sort), expectedFields);
}, {
...GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [7, 4]
});

testUtils.testWithClient('sScanIterator', async client => {
const members = new Set<string>();
for (let i = 0; i < 100; i++) {
Expand Down
13 changes: 13 additions & 0 deletions packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,19 @@ export default class RedisClient<
} while (cursor !== '0');
}

async* hScanNoValuesIterator(
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(
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
key: RedisArgument,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/commands/HPERSIST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
return pushVariadicArgument(['HPERSIST', key, 'FIELDS'], fields);
},
transformReply: undefined as unknown as () => ArrayReply<NumberReply> | NullReply
} as const satisfies Command;
} as const satisfies Command;
2 changes: 1 addition & 1 deletion packages/client/lib/commands/HPEXPIRE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export default {
return pushVariadicArgument(args, fields);
},
transformReply: undefined as unknown as () => ArrayReply<HashExpiration> | NullReply
} as const satisfies Command;
} as const satisfies Command;
2 changes: 1 addition & 1 deletion packages/client/lib/commands/HPEXPIREAT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export default {
return pushVariadicArgument(args, fields);
},
transformReply: undefined as unknown as () => ArrayReply<HashExpiration> | NullReply
} as const satisfies Command;
} as const satisfies Command;
2 changes: 1 addition & 1 deletion packages/client/lib/commands/HPEXPIRETIME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
return pushVariadicArgument(['HPEXPIRETIME', key, 'FIELDS'], fields);
},
transformReply: undefined as unknown as () => ArrayReply<NumberReply> | NullReply
} as const satisfies Command;
} as const satisfies Command;
25 changes: 25 additions & 0 deletions packages/client/lib/commands/HSCAN.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ describe('HSCAN', () => {
});
});

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

it('with tuples', () => {
assert.deepEqual(
HSCAN.transformReply(['0' as any, ['field', 'value'] as any]),
{
cursor: '0',
entries: [{
field: 'field',
value: 'value'
}]
}
);
});
});

testUtils.testWithClient('client.hScan', async client => {
const [, reply] = await Promise.all([
client.hSet('key', 'field', 'value'),
Expand Down
26 changes: 25 additions & 1 deletion packages/client/lib/commands/HSCAN_NOVALUES.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HSCAN_NOVALUES from './HSCAN_NOVALUES';
import { BlobStringReply } from '../RESP/types';

describe('HSCAN_NOVALUES', () => {
testUtils.isVersionGreaterThanHook([7.4]);
testUtils.isVersionGreaterThanHook([7,4]);

describe('transformArguments', () => {
it('cusror only', () => {
Expand Down Expand Up @@ -42,6 +43,29 @@ describe('HSCAN_NOVALUES', () => {
});
});

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'),
Expand Down
24 changes: 24 additions & 0 deletions packages/search/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ describe('FT.CREATE', () => {
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TAG', 'WITHSUFFIXTRIE']
);
});

it('with INDEXEMPTY', () => {
assert.deepEqual(
CREATE.transformArguments('index', {
field: {
type: SCHEMA_FIELD_TYPE.TAG,
INDEXEMPTY: true
}
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TAG', 'INDEXEMPTY']
);
});
});

describe('VECTOR', () => {
Expand Down Expand Up @@ -280,6 +292,18 @@ describe('FT.CREATE', () => {
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'NOINDEX']
);
});

it('with INDEXMISSING', () => {
assert.deepEqual(
CREATE.transformArguments('index', {
field: {
type: SCHEMA_FIELD_TYPE.TEXT,
INDEXMISSING: true
}
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'INDEXMISSING']
);
});
});

it('with ON', () => {
Expand Down
Loading

0 comments on commit 1dc6d8e

Please sign in to comment.