You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
fix for 6ca420f15e
- fix cursor, add tests
This commit is contained in:
@@ -11,6 +11,7 @@ import { once } from 'events';
|
|||||||
// import { promisify } from 'util';
|
// import { promisify } from 'util';
|
||||||
import { MATH_FUNCTION, loadMathFunction } from '../commands/FUNCTION_LOAD.spec';
|
import { MATH_FUNCTION, loadMathFunction } from '../commands/FUNCTION_LOAD.spec';
|
||||||
import { RESP_TYPES } from '../RESP/decoder';
|
import { RESP_TYPES } from '../RESP/decoder';
|
||||||
|
import { SortedSetMember } from '../commands/generic-transformers';
|
||||||
|
|
||||||
export const SQUARE_SCRIPT = defineScript({
|
export const SQUARE_SCRIPT = defineScript({
|
||||||
SCRIPT: 'return ARGV[1] * ARGV[1];',
|
SCRIPT: 'return ARGV[1] * ARGV[1];',
|
||||||
@@ -435,84 +436,84 @@ describe('Client', () => {
|
|||||||
// return client.executeIsolated(isolated => killClient(isolated, client));
|
// return client.executeIsolated(isolated => killClient(isolated, client));
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
// }, GLOBAL.SERVERS.OPEN);
|
||||||
|
|
||||||
// testUtils.testWithClient('scanIterator', async client => {
|
testUtils.testWithClient('scanIterator', async client => {
|
||||||
// const promises = [],
|
const promises = [],
|
||||||
// keys = new Set();
|
keys = new Set();
|
||||||
// for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
// const key = i.toString();
|
const key = i.toString();
|
||||||
// keys.add(key);
|
keys.add(key);
|
||||||
// promises.push(client.set(key, ''));
|
promises.push(client.set(key, ''));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
||||||
// const results = new Set();
|
const results = new Set();
|
||||||
// for await (const key of client.scanIterator()) {
|
for await (const keys of client.scanIterator()) {
|
||||||
// results.add(key);
|
results.add(...keys);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// assert.deepEqual(keys, results);
|
assert.deepEqual(keys, results);
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
|
||||||
// testUtils.testWithClient('hScanIterator', async client => {
|
testUtils.testWithClient('hScanIterator', async client => {
|
||||||
// const hash: Record<string, string> = {};
|
const hash: Record<string, string> = {};
|
||||||
// for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
// hash[i.toString()] = i.toString();
|
hash[i.toString()] = i.toString();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await client.hSet('key', hash);
|
await client.hSet('key', hash);
|
||||||
|
|
||||||
// const results: Record<string, string> = {};
|
const results: Record<string, string> = {};
|
||||||
// for await (const { field, value } of client.hScanIterator('key')) {
|
for await (const entries of client.hScanIterator('key')) {
|
||||||
// results[field] = value;
|
for (const [field, value] of entries) {
|
||||||
// }
|
results[field] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// assert.deepEqual(hash, results);
|
assert.deepEqual(hash, results);
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
|
||||||
// testUtils.testWithClient('sScanIterator', async client => {
|
testUtils.testWithClient('sScanIterator', async client => {
|
||||||
// const members = new Set<string>();
|
const members = new Set<string>();
|
||||||
// for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
// members.add(i.toString());
|
members.add(i.toString());
|
||||||
// }
|
}
|
||||||
|
|
||||||
// await client.sAdd('key', Array.from(members));
|
await client.sAdd('key', Array.from(members));
|
||||||
|
|
||||||
// const results = new Set<string>();
|
const results = new Set<string>();
|
||||||
// for await (const key of client.sScanIterator('key')) {
|
for await (const members of client.sScanIterator('key')) {
|
||||||
// results.add(key);
|
for (const member of members) {
|
||||||
// }
|
results.add(member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// assert.deepEqual(members, results);
|
assert.deepEqual(members, results);
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
|
||||||
// testUtils.testWithClient('zScanIterator', async client => {
|
testUtils.testWithClient('zScanIterator', async client => {
|
||||||
// const members = [];
|
const members: Array<SortedSetMember> = [],
|
||||||
// for (let i = 0; i < 100; i++) {
|
map = new Map<string, number>();
|
||||||
// members.push({
|
for (let i = 0; i < 100; i++) {
|
||||||
// score: 1,
|
const member = {
|
||||||
// value: i.toString()
|
value: i.toString(),
|
||||||
// });
|
score: 1
|
||||||
// }
|
};
|
||||||
|
map.set(member.value, member.score);
|
||||||
|
members.push(member);
|
||||||
|
}
|
||||||
|
|
||||||
// await client.zAdd('key', members);
|
await client.zAdd('key', members);
|
||||||
|
|
||||||
// const map = new Map<string, number>();
|
const results = new Map<string, number>();
|
||||||
// for await (const member of client.zScanIterator('key')) {
|
for await (const members of client.zScanIterator('key')) {
|
||||||
// map.set(member.value, member.score);
|
for (const { value, score } of members) {
|
||||||
// }
|
results.set(value, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// type MemberTuple = [string, number];
|
assert.deepEqual(members, results);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
// function sort(a: MemberTuple, b: MemberTuple) {
|
|
||||||
// return Number(b[0]) - Number(a[0]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// assert.deepEqual(
|
|
||||||
// [...map.entries()].sort(sort),
|
|
||||||
// members.map<MemberTuple>(member => [member.value, member.score]).sort(sort)
|
|
||||||
// );
|
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
|
||||||
|
|
||||||
// describe('PubSub', () => {
|
// describe('PubSub', () => {
|
||||||
// testUtils.testWithClient('should be able to publish and subscribe to messages', async publisher => {
|
// testUtils.testWithClient('should be able to publish and subscribe to messages', async publisher => {
|
||||||
|
@@ -141,7 +141,7 @@ type ProxyClient = RedisClient<any, any, any, any, any>;
|
|||||||
type NamespaceProxyClient = { self: ProxyClient };
|
type NamespaceProxyClient = { self: ProxyClient };
|
||||||
|
|
||||||
interface ScanIteratorOptions {
|
interface ScanIteratorOptions {
|
||||||
cursor?: number;
|
cursor?: RedisArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class RedisClient<
|
export default class RedisClient<
|
||||||
@@ -799,12 +799,12 @@ export default class RedisClient<
|
|||||||
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
|
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
|
||||||
options?: ScanOptions & ScanIteratorOptions
|
options?: ScanOptions & ScanIteratorOptions
|
||||||
) {
|
) {
|
||||||
let cursor = options?.cursor ?? 0;
|
let cursor = options?.cursor ?? '0';
|
||||||
do {
|
do {
|
||||||
const reply = await this.scan(cursor, options);
|
const reply = await this.scan(cursor, options);
|
||||||
cursor = reply.cursor;
|
cursor = reply.cursor;
|
||||||
yield reply.keys;
|
yield reply.keys;
|
||||||
} while (cursor !== 0);
|
} while (cursor !== '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
async* hScanIterator(
|
async* hScanIterator(
|
||||||
@@ -812,12 +812,12 @@ export default class RedisClient<
|
|||||||
key: RedisArgument,
|
key: RedisArgument,
|
||||||
options?: ScanCommonOptions & ScanIteratorOptions
|
options?: ScanCommonOptions & ScanIteratorOptions
|
||||||
) {
|
) {
|
||||||
let cursor = options?.cursor ?? 0;
|
let cursor = options?.cursor ?? '0';
|
||||||
do {
|
do {
|
||||||
const reply = await this.hScan(key, cursor, options);
|
const reply = await this.hScan(key, cursor, options);
|
||||||
cursor = reply.cursor;
|
cursor = reply.cursor;
|
||||||
yield reply.entries;
|
yield reply.entries;
|
||||||
} while (cursor !== 0);
|
} while (cursor !== '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
async* sScanIterator(
|
async* sScanIterator(
|
||||||
@@ -825,12 +825,12 @@ export default class RedisClient<
|
|||||||
key: RedisArgument,
|
key: RedisArgument,
|
||||||
options?: ScanCommonOptions & ScanIteratorOptions
|
options?: ScanCommonOptions & ScanIteratorOptions
|
||||||
) {
|
) {
|
||||||
let cursor = options?.cursor ?? 0;
|
let cursor = options?.cursor ?? '0';
|
||||||
do {
|
do {
|
||||||
const reply = await this.sScan(key, cursor, options);
|
const reply = await this.sScan(key, cursor, options);
|
||||||
cursor = reply.cursor;
|
cursor = reply.cursor;
|
||||||
yield reply.members;
|
yield reply.members;
|
||||||
} while (cursor !== 0);
|
} while (cursor !== '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
async* zScanIterator(
|
async* zScanIterator(
|
||||||
@@ -838,12 +838,12 @@ export default class RedisClient<
|
|||||||
key: RedisArgument,
|
key: RedisArgument,
|
||||||
options?: ScanCommonOptions & ScanIteratorOptions
|
options?: ScanCommonOptions & ScanIteratorOptions
|
||||||
) {
|
) {
|
||||||
let cursor = options?.cursor ?? 0;
|
let cursor = options?.cursor ?? '0';
|
||||||
do {
|
do {
|
||||||
const reply = await this.zScan(key, cursor, options);
|
const reply = await this.zScan(key, cursor, options);
|
||||||
cursor = reply.cursor;
|
cursor = reply.cursor;
|
||||||
yield reply.members;
|
yield reply.members;
|
||||||
} while (cursor !== 0);
|
} while (cursor !== '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user