Skip to content

Commit

Permalink
Merge branch 'v5' of github.com:leibale/node-redis into v5
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale committed May 8, 2023
2 parents 01e6821 + d5ef578 commit c6f9f6e
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 186 deletions.
1 change: 1 addition & 0 deletions docs/v4-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Some command arguments/replies have changed to align more closely to data types
- `SCRIPT EXISTS`: `Array<boolean>` -> `Array<number>` [^boolean-to-number]
- `SISMEMBER`: `boolean` -> `number` [^boolean-to-number]
- `SMISMEMBER`: `Array<boolean>` -> `Array<number>` [^boolean-to-number]
- `SMOVE`: `boolean` -> `number` [^boolean-to-number]
- `TS.ADD`: `boolean` -> `number` [^boolean-to-number]
- `GEOSEARCH_WITH`/`GEORADIUS_WITH`: `GeoReplyWith` -> `GEO_REPLY_WITH` [^enum-to-constants]
- `GEORADIUSSTORE` -> `GEORADIUS_STORE`
Expand Down
73 changes: 38 additions & 35 deletions packages/client/lib/commands/BITCOUNT.spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './BITCOUNT';
import BITCOUNT from './BITCOUNT';

describe('BITCOUNT', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key'),
['BITCOUNT', 'key']
);
});
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
BITCOUNT.transformArguments('key'),
['BITCOUNT', 'key']
);
});

describe('with range', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key', {
start: 0,
end: 1
}),
['BITCOUNT', 'key', '0', '1']
);
});
describe('with range', () => {
it('simple', () => {
assert.deepEqual(
BITCOUNT.transformArguments('key', {
start: 0,
end: 1
}),
['BITCOUNT', 'key', '0', '1']
);
});

it('with mode', () => {
assert.deepEqual(
transformArguments('key', {
start: 0,
end: 1,
mode: 'BIT'
}),
['BITCOUNT', 'key', '0', '1', 'BIT']
);
});
});
it('with mode', () => {
assert.deepEqual(
BITCOUNT.transformArguments('key', {
start: 0,
end: 1,
mode: 'BIT'
}),
['BITCOUNT', 'key', '0', '1', 'BIT']
);
});
});
});

testUtils.testWithClient('client.bitCount', async client => {
assert.equal(
await client.bitCount('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testAll('bitCount', async client => {
assert.equal(
await client.bitCount('key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
76 changes: 36 additions & 40 deletions packages/client/lib/commands/BITPOS.spec.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './BITPOS';
import BITPOS from './BITPOS';

describe('BITPOS', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key', 1),
['BITPOS', 'key', '1']
);
});

it('with start', () => {
assert.deepEqual(
transformArguments('key', 1, 1),
['BITPOS', 'key', '1', '1']
);
});
describe.only('BITPOS', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
BITPOS.transformArguments('key', 1),
['BITPOS', 'key', '1']
);
});

it('with start and end', () => {
assert.deepEqual(
transformArguments('key', 1, 1, -1),
['BITPOS', 'key', '1', '1', '-1']
);
});
it('with start', () => {
assert.deepEqual(
BITPOS.transformArguments('key', 1, 1),
['BITPOS', 'key', '1', '1']
);
});

it('with start, end and mode', () => {
assert.deepEqual(
transformArguments('key', 1, 1, -1, 'BIT'),
['BITPOS', 'key', '1', '1', '-1', 'BIT']
);
});
it('with start and end', () => {
assert.deepEqual(
BITPOS.transformArguments('key', 1, 1, -1),
['BITPOS', 'key', '1', '1', '-1']
);
});

testUtils.testWithClient('client.bitPos', async client => {
assert.equal(
await client.bitPos('key', 1, 1),
-1
);
}, GLOBAL.SERVERS.OPEN);
it('with start, end and mode', () => {
assert.deepEqual(
BITPOS.transformArguments('key', 1, 1, -1, 'BIT'),
['BITPOS', 'key', '1', '1', '-1', 'BIT']
);
});
});

testUtils.testWithCluster('cluster.bitPos', async cluster => {
assert.equal(
await cluster.bitPos('key', 1, 1),
-1
);
}, GLOBAL.CLUSTERS.OPEN);
testUtils.testAll('bitPos', async client => {
assert.equal(
await client.bitPos('key', 1, 1),
-1
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
1 change: 0 additions & 1 deletion packages/client/lib/commands/LRANGE.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import LRANGE from './LRANGE';
Expand Down
1 change: 0 additions & 1 deletion packages/client/lib/commands/LREM.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import LREM from './LREM';
Expand Down
37 changes: 20 additions & 17 deletions packages/client/lib/commands/SMOVE.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// import { strict as assert } from 'assert';
// import testUtils, { GLOBAL } from '../test-utils';
// import { transformArguments } from './SMOVE';
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import SMOVE from './SMOVE';

// describe('SMOVE', () => {
// it('transformArguments', () => {
// assert.deepEqual(
// transformArguments('source', 'destination', 'member'),
// ['SMOVE', 'source', 'destination', 'member']
// );
// });
describe('SMOVE', () => {
it('transformArguments', () => {
assert.deepEqual(
SMOVE.transformArguments('source', 'destination', 'member'),
['SMOVE', 'source', 'destination', 'member']
);
});

// testUtils.testWithClient('client.sMove', async client => {
// assert.equal(
// await client.sMove('source', 'destination', 'member'),
// false
// );
// }, GLOBAL.SERVERS.OPEN);
// });
testUtils.testAll('sMove', async client => {
assert.equal(
await client.sMove('{tag}source', '{tag}destination', 'member'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
25 changes: 13 additions & 12 deletions packages/client/lib/commands/SMOVE.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// import { RedisCommandArgument, RedisCommandArguments } from '.';
import { RedisArgument, NumberReply, Command } from '../RESP/types';

// export const FIRST_KEY_INDEX = 1;

// export function transformArguments(
// source: RedisCommandArgument,
// destination: RedisCommandArgument,
// member: RedisCommandArgument
// ): RedisCommandArguments {
// return ['SMOVE', source, destination, member];
// }

// export { transformBooleanReply as transformReply } from './generic-transformers';
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(
source: RedisArgument,
destination: RedisArgument,
member: RedisArgument
) {
return ['SMOVE', source, destination, member];
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;
7 changes: 5 additions & 2 deletions packages/client/lib/commands/SSCAN.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ describe('SSCAN', () => {
});
});

testUtils.testWithClient('client.sScan', async client => {
testUtils.testAll('sScan', async client => {
assert.deepEqual(
await client.sScan('key', 0),
{
cursor: 0,
members: []
}
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
53 changes: 28 additions & 25 deletions packages/client/lib/commands/SUNION.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
// import { strict as assert } from 'assert';
// import testUtils, { GLOBAL } from '../test-utils';
// import { transformArguments } from './SUNION';
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import SUNION from './SUNION';

// describe('SUNION', () => {
// describe('transformArguments', () => {
// it('string', () => {
// assert.deepEqual(
// transformArguments('key'),
// ['SUNION', 'key']
// );
// });
describe('SUNION', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
SUNION.transformArguments('key'),
['SUNION', 'key']
);
});

// it('array', () => {
// assert.deepEqual(
// transformArguments(['1', '2']),
// ['SUNION', '1', '2']
// );
// });
// });
it('array', () => {
assert.deepEqual(
SUNION.transformArguments(['1', '2']),
['SUNION', '1', '2']
);
});
});

// testUtils.testWithClient('client.sUnion', async client => {
// assert.deepEqual(
// await client.sUnion('key'),
// []
// );
// }, GLOBAL.SERVERS.OPEN);
// });
testUtils.testAll('sUnion', async client => {
assert.deepEqual(
await client.sUnion('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
25 changes: 11 additions & 14 deletions packages/client/lib/commands/SUNION.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// import { RedisCommandArgument, RedisCommandArguments } from '.';
// import { pushVariadicArguments } from './generic-transformers';

// export const FIRST_KEY_INDEX = 1;

// export const IS_READ_ONLY = true;

// export function transformArguments(
// keys: RedisCommandArgument | Array<RedisCommandArgument>
// ): RedisCommandArguments {
// return pushVariadicArguments(['SUNION'], keys);
// }

// export declare function transformReply(): Array<RedisCommandArgument>;
import { ArrayReply, BlobStringReply, Command } from '../RESP/types';
import { RedisVariadicArgument, pushVariadicArguments } from './generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(keys: RedisVariadicArgument) {
return pushVariadicArguments(['SUNION'], keys);
},
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
} as const satisfies Command;
Loading

0 comments on commit c6f9f6e

Please sign in to comment.