Skip to content

Commit 442a554

Browse files
committed
WIP
1 parent 13f1fa9 commit 442a554

18 files changed

+272
-221
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { transformArguments } from './ECHO';
3+
import ECHO from './ECHO';
44

55
describe('ECHO', () => {
6-
it('transformArguments', () => {
7-
assert.deepEqual(
8-
transformArguments('message'),
9-
['ECHO', 'message']
10-
);
11-
});
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
ECHO.transformArguments('message'),
9+
['ECHO', 'message']
10+
);
11+
});
1212

13-
testUtils.testWithClient('client.echo', async client => {
14-
assert.equal(
15-
await client.echo('message'),
16-
'message'
17-
);
18-
}, GLOBAL.SERVERS.OPEN);
13+
testUtils.testWithClient('client.echo', async client => {
14+
assert.equal(
15+
await client.echo('message'),
16+
'message'
17+
);
18+
}, GLOBAL.SERVERS.OPEN);
1919
});
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { transformArguments } from './EVAL';
3+
import EVAL from './EVAL';
44

55
describe('EVAL', () => {
6-
it('transformArguments', () => {
7-
assert.deepEqual(
8-
transformArguments('return KEYS[1] + ARGV[1]', {
9-
keys: ['key'],
10-
arguments: ['argument']
11-
}),
12-
['EVAL', 'return KEYS[1] + ARGV[1]', '1', 'key', 'argument']
13-
);
14-
});
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
EVAL.transformArguments('return KEYS[1] + ARGV[1]', {
9+
keys: ['key'],
10+
arguments: ['argument']
11+
}),
12+
['EVAL', 'return KEYS[1] + ARGV[1]', '1', 'key', 'argument']
13+
);
14+
});
1515

16-
testUtils.testWithClient('client.eval', async client => {
17-
assert.equal(
18-
await client.eval('return 1'),
19-
1
20-
);
21-
}, GLOBAL.SERVERS.OPEN);
22-
23-
testUtils.testWithCluster('cluster.eval', async cluster => {
24-
assert.equal(
25-
await cluster.eval('return 1'),
26-
1
27-
);
28-
}, GLOBAL.CLUSTERS.OPEN);
16+
testUtils.testAll('eval', async client => {
17+
assert.equal(
18+
await client.eval('return 1'),
19+
1
20+
);
21+
}, {
22+
client: GLOBAL.SERVERS.OPEN,
23+
cluster: GLOBAL.CLUSTERS.OPEN
24+
});
2925
});

packages/client/lib/commands/EVAL.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
1+
import { RedisArgument, ReplyUnion, Command } from '../RESP/types';
22

3-
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
3+
export interface EvalOptions {
4+
keys?: Array<RedisArgument>;
5+
arguments?: Array<RedisArgument>;
6+
}
7+
8+
export function transformEvalArguments(
9+
command: RedisArgument,
10+
script: RedisArgument,
11+
options?: EvalOptions
12+
) {
13+
const args = [command, script];
14+
15+
if (options?.keys) {
16+
args.push(options.keys.length.toString(), ...options.keys);
17+
} else {
18+
args.push('0');
19+
}
420

5-
export function transformArguments(script: string, options?: EvalOptions): Array<string> {
6-
return pushEvalArguments(['EVAL', script], options);
21+
if (options?.arguments) {
22+
args.push(...options.arguments);
23+
}
24+
25+
return args;
726
}
27+
28+
export default {
29+
FIRST_KEY_INDEX: (_, options?: EvalOptions) => options?.keys?.[0],
30+
IS_READ_ONLY: false,
31+
transformArguments: transformEvalArguments.bind(undefined, 'EVAL'),
32+
transformReply: undefined as unknown as () => ReplyUnion
33+
} as const satisfies Command;
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { strict as assert } from 'assert';
2-
import { transformArguments } from './EVALSHA';
2+
import EVALSHA from './EVALSHA';
33

44
describe('EVALSHA', () => {
5-
it('transformArguments', () => {
6-
assert.deepEqual(
7-
transformArguments('sha1', {
8-
keys: ['key'],
9-
arguments: ['argument']
10-
}),
11-
['EVALSHA', 'sha1', '1', 'key', 'argument']
12-
);
13-
});
5+
it('transformArguments', () => {
6+
assert.deepEqual(
7+
EVALSHA.transformArguments('sha1', {
8+
keys: ['key'],
9+
arguments: ['argument']
10+
}),
11+
['EVALSHA', 'sha1', '1', 'key', 'argument']
12+
);
13+
});
1414
});
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
1+
import { Command } from '../RESP/types';
2+
import EVAL, { transformEvalArguments } from './EVAL';
23

3-
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
4-
5-
export function transformArguments(sha1: string, options?: EvalOptions): Array<string> {
6-
return pushEvalArguments(['EVALSHA', sha1], options);
7-
}
4+
export default {
5+
FIRST_KEY_INDEX: EVAL.FIRST_KEY_INDEX,
6+
IS_READ_ONLY: false,
7+
transformArguments: transformEvalArguments.bind(undefined, 'EVALSHA'),
8+
transformReply: EVAL.transformReply
9+
} as const satisfies Command;
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { strict as assert } from 'assert';
22
import testUtils from '../test-utils';
3-
import { transformArguments } from './EVALSHA_RO';
3+
import EVALSHA_RO from './EVALSHA_RO';
44

55
describe('EVALSHA_RO', () => {
6-
testUtils.isVersionGreaterThanHook([7]);
6+
testUtils.isVersionGreaterThanHook([7]);
77

8-
it('transformArguments', () => {
9-
assert.deepEqual(
10-
transformArguments('sha1', {
11-
keys: ['key'],
12-
arguments: ['argument']
13-
}),
14-
['EVALSHA_RO', 'sha1', '1', 'key', 'argument']
15-
);
16-
});
8+
it('transformArguments', () => {
9+
assert.deepEqual(
10+
EVALSHA_RO.transformArguments('sha1', {
11+
keys: ['key'],
12+
arguments: ['argument']
13+
}),
14+
['EVALSHA_RO', 'sha1', '1', 'key', 'argument']
15+
);
16+
});
1717
});
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
1+
import { Command } from '../RESP/types';
2+
import EVAL, { transformEvalArguments } from './EVAL';
23

3-
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
4-
5-
export const IS_READ_ONLY = true;
6-
7-
export function transformArguments(sha1: string, options?: EvalOptions): Array<string> {
8-
return pushEvalArguments(['EVALSHA_RO', sha1], options);
9-
}
4+
export default {
5+
FIRST_KEY_INDEX: EVAL.FIRST_KEY_INDEX,
6+
IS_READ_ONLY: true,
7+
transformArguments: transformEvalArguments.bind(undefined, 'EVALSHA_RO'),
8+
transformReply: EVAL.transformReply
9+
} as const satisfies Command;
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { transformArguments } from './EVAL_RO';
3+
import EVAL_RO from './EVAL_RO';
44

55
describe('EVAL_RO', () => {
6-
testUtils.isVersionGreaterThanHook([7]);
6+
testUtils.isVersionGreaterThanHook([7]);
77

8-
it('transformArguments', () => {
9-
assert.deepEqual(
10-
transformArguments('return KEYS[1] + ARGV[1]', {
11-
keys: ['key'],
12-
arguments: ['argument']
13-
}),
14-
['EVAL_RO', 'return KEYS[1] + ARGV[1]', '1', 'key', 'argument']
15-
);
16-
});
8+
it('transformArguments', () => {
9+
assert.deepEqual(
10+
EVAL_RO.transformArguments('return KEYS[1] + ARGV[1]', {
11+
keys: ['key'],
12+
arguments: ['argument']
13+
}),
14+
['EVAL_RO', 'return KEYS[1] + ARGV[1]', '1', 'key', 'argument']
15+
);
16+
});
1717

18-
testUtils.testWithClient('client.evalRo', async client => {
19-
assert.equal(
20-
await client.evalRo('return 1'),
21-
1
22-
);
23-
}, GLOBAL.SERVERS.OPEN);
24-
25-
testUtils.testWithCluster('cluster.evalRo', async cluster => {
26-
assert.equal(
27-
await cluster.evalRo('return 1'),
28-
1
29-
);
30-
}, GLOBAL.CLUSTERS.OPEN);
18+
testUtils.testAll('evalRo', async cluster => {
19+
assert.equal(
20+
await cluster.evalRo('return 1'),
21+
1
22+
);
23+
}, {
24+
client: GLOBAL.SERVERS.OPEN,
25+
cluster: GLOBAL.CLUSTERS.OPEN
26+
});
3127
});
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
1+
import { Command } from '../RESP/types';
2+
import EVAL, { transformEvalArguments } from './EVAL';
23

3-
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
4-
5-
export const IS_READ_ONLY = true;
6-
7-
export function transformArguments(script: string, options?: EvalOptions): Array<string> {
8-
return pushEvalArguments(['EVAL_RO', script], options);
9-
}
4+
export default {
5+
FIRST_KEY_INDEX: EVAL.FIRST_KEY_INDEX,
6+
IS_READ_ONLY: true,
7+
transformArguments: transformEvalArguments.bind(undefined, 'EVAL_RO'),
8+
transformReply: EVAL.transformReply
9+
} as const satisfies Command;

packages/client/lib/commands/FCALL.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ export const FIRST_KEY_INDEX = evalFirstKeyIndex;
55
export function transformArguments(fn: string, options?: EvalOptions): Array<string> {
66
return pushEvalArguments(['FCALL', fn], options);
77
}
8+
9+
import { SimpleStringReply, Command } from '../RESP/types';
10+
11+
export default {
12+
FIRST_KEY_INDEX: undefined,
13+
IS_READ_ONLY: false,
14+
transformArguments() {
15+
return ['FCALL'];
16+
},
17+
transformReply: undefined as unknown as () => SimpleStringReply
18+
} as const satisfies Command;
19+

0 commit comments

Comments
 (0)