You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
WIP
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ECHO';
|
||||
import ECHO from './ECHO';
|
||||
|
||||
describe('ECHO', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('message'),
|
||||
ECHO.transformArguments('message'),
|
||||
['ECHO', 'message']
|
||||
);
|
||||
});
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './EVAL';
|
||||
import EVAL from './EVAL';
|
||||
|
||||
describe('EVAL', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('return KEYS[1] + ARGV[1]', {
|
||||
EVAL.transformArguments('return KEYS[1] + ARGV[1]', {
|
||||
keys: ['key'],
|
||||
arguments: ['argument']
|
||||
}),
|
||||
@@ -13,17 +13,13 @@ describe('EVAL', () => {
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.eval', async client => {
|
||||
testUtils.testAll('eval', async client => {
|
||||
assert.equal(
|
||||
await client.eval('return 1'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.eval', async cluster => {
|
||||
assert.equal(
|
||||
await cluster.eval('return 1'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,33 @@
|
||||
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
|
||||
import { RedisArgument, ReplyUnion, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
|
||||
|
||||
export function transformArguments(script: string, options?: EvalOptions): Array<string> {
|
||||
return pushEvalArguments(['EVAL', script], options);
|
||||
export interface EvalOptions {
|
||||
keys?: Array<RedisArgument>;
|
||||
arguments?: Array<RedisArgument>;
|
||||
}
|
||||
|
||||
export function transformEvalArguments(
|
||||
command: RedisArgument,
|
||||
script: RedisArgument,
|
||||
options?: EvalOptions
|
||||
) {
|
||||
const args = [command, script];
|
||||
|
||||
if (options?.keys) {
|
||||
args.push(options.keys.length.toString(), ...options.keys);
|
||||
} else {
|
||||
args.push('0');
|
||||
}
|
||||
|
||||
if (options?.arguments) {
|
||||
args.push(...options.arguments);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: (_, options?: EvalOptions) => options?.keys?.[0],
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments: transformEvalArguments.bind(undefined, 'EVAL'),
|
||||
transformReply: undefined as unknown as () => ReplyUnion
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './EVALSHA';
|
||||
import EVALSHA from './EVALSHA';
|
||||
|
||||
describe('EVALSHA', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('sha1', {
|
||||
EVALSHA.transformArguments('sha1', {
|
||||
keys: ['key'],
|
||||
arguments: ['argument']
|
||||
}),
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
|
||||
import { Command } from '../RESP/types';
|
||||
import EVAL, { transformEvalArguments } from './EVAL';
|
||||
|
||||
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
|
||||
|
||||
export function transformArguments(sha1: string, options?: EvalOptions): Array<string> {
|
||||
return pushEvalArguments(['EVALSHA', sha1], options);
|
||||
}
|
||||
export default {
|
||||
FIRST_KEY_INDEX: EVAL.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments: transformEvalArguments.bind(undefined, 'EVALSHA'),
|
||||
transformReply: EVAL.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './EVALSHA_RO';
|
||||
import EVALSHA_RO from './EVALSHA_RO';
|
||||
|
||||
describe('EVALSHA_RO', () => {
|
||||
testUtils.isVersionGreaterThanHook([7]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('sha1', {
|
||||
EVALSHA_RO.transformArguments('sha1', {
|
||||
keys: ['key'],
|
||||
arguments: ['argument']
|
||||
}),
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
|
||||
import { Command } from '../RESP/types';
|
||||
import EVAL, { transformEvalArguments } from './EVAL';
|
||||
|
||||
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(sha1: string, options?: EvalOptions): Array<string> {
|
||||
return pushEvalArguments(['EVALSHA_RO', sha1], options);
|
||||
}
|
||||
export default {
|
||||
FIRST_KEY_INDEX: EVAL.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: transformEvalArguments.bind(undefined, 'EVALSHA_RO'),
|
||||
transformReply: EVAL.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './EVAL_RO';
|
||||
import EVAL_RO from './EVAL_RO';
|
||||
|
||||
describe('EVAL_RO', () => {
|
||||
testUtils.isVersionGreaterThanHook([7]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('return KEYS[1] + ARGV[1]', {
|
||||
EVAL_RO.transformArguments('return KEYS[1] + ARGV[1]', {
|
||||
keys: ['key'],
|
||||
arguments: ['argument']
|
||||
}),
|
||||
@@ -15,17 +15,13 @@ describe('EVAL_RO', () => {
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.evalRo', async client => {
|
||||
assert.equal(
|
||||
await client.evalRo('return 1'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithCluster('cluster.evalRo', async cluster => {
|
||||
testUtils.testAll('evalRo', async cluster => {
|
||||
assert.equal(
|
||||
await cluster.evalRo('return 1'),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { evalFirstKeyIndex, EvalOptions, pushEvalArguments } from './generic-transformers';
|
||||
import { Command } from '../RESP/types';
|
||||
import EVAL, { transformEvalArguments } from './EVAL';
|
||||
|
||||
export const FIRST_KEY_INDEX = evalFirstKeyIndex;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(script: string, options?: EvalOptions): Array<string> {
|
||||
return pushEvalArguments(['EVAL_RO', script], options);
|
||||
}
|
||||
export default {
|
||||
FIRST_KEY_INDEX: EVAL.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments: transformEvalArguments.bind(undefined, 'EVAL_RO'),
|
||||
transformReply: EVAL.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -5,3 +5,15 @@ export const FIRST_KEY_INDEX = evalFirstKeyIndex;
|
||||
export function transformArguments(fn: string, options?: EvalOptions): Array<string> {
|
||||
return pushEvalArguments(['FCALL', fn], options);
|
||||
}
|
||||
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments() {
|
||||
return ['FCALL'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './HELLO';
|
||||
import HELLO from './HELLO';
|
||||
|
||||
describe('HELLO', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
@@ -8,25 +8,22 @@ describe('HELLO', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
HELLO.transformArguments(),
|
||||
['HELLO']
|
||||
);
|
||||
});
|
||||
|
||||
it('with protover', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
protover: 3
|
||||
}),
|
||||
HELLO.transformArguments(3),
|
||||
['HELLO', '3']
|
||||
);
|
||||
});
|
||||
|
||||
it('with protover, auth', () => {
|
||||
it('with protover, AUTH', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
protover: 3,
|
||||
auth: {
|
||||
HELLO.transformArguments(3, {
|
||||
AUTH: {
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
}
|
||||
@@ -35,27 +32,25 @@ describe('HELLO', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('with protover, clientName', () => {
|
||||
it('with protover, SETNAME', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
protover: 3,
|
||||
clientName: 'clientName'
|
||||
HELLO.transformArguments(3, {
|
||||
SETNAME: 'name'
|
||||
}),
|
||||
['HELLO', '3', 'SETNAME', 'clientName']
|
||||
['HELLO', '3', 'SETNAME', 'name']
|
||||
);
|
||||
});
|
||||
|
||||
it('with protover, auth, clientName', () => {
|
||||
it('with protover, AUTH, SETNAME', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
protover: 3,
|
||||
auth: {
|
||||
HELLO.transformArguments(3, {
|
||||
AUTH: {
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
},
|
||||
clientName: 'clientName'
|
||||
SETNAME: 'name'
|
||||
}),
|
||||
['HELLO', '3', 'AUTH', 'username', 'password', 'SETNAME', 'clientName']
|
||||
['HELLO', '3', 'AUTH', 'username', 'password', 'SETNAME', 'name']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, Command, NumberReply, Resp2Reply, RespVersions, TuplesToMapReply } from '../RESP/types';
|
||||
|
||||
export interface HelloOptions {
|
||||
protover?: RespVersions;
|
||||
AUTH?: {
|
||||
username: RedisArgument;
|
||||
password: RedisArgument;
|
||||
@@ -19,8 +20,11 @@ export type HelloReply = TuplesToMapReply<[
|
||||
]>;
|
||||
|
||||
export default {
|
||||
transformArguments(protoover: RespVersions, options?: HelloOptions) {
|
||||
const args: Array<RedisArgument> = ['HELLO', protoover.toString()];
|
||||
transformArguments(protover?: RespVersions, options?: HelloOptions) {
|
||||
const args: Array<RedisArgument> = ['HELLO'];
|
||||
|
||||
if (protover) {
|
||||
args.push(protover.toString());
|
||||
|
||||
if (options?.AUTH) {
|
||||
args.push(
|
||||
@@ -36,6 +40,7 @@ export default {
|
||||
options.SETNAME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './LASTSAVE';
|
||||
import LASTSAVE from './LASTSAVE';
|
||||
|
||||
describe('LASTSAVE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
LASTSAVE.transformArguments(),
|
||||
['LASTSAVE']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.lastSave', async client => {
|
||||
assert.ok((await client.lastSave()) instanceof Date);
|
||||
assert.ok(typeof await client.lastSave() === 'number');
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,9 +1,10 @@
|
||||
export const IS_READ_ONLY = true;
|
||||
import { NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['LASTSAVE'];
|
||||
}
|
||||
|
||||
export function transformReply(reply: number): Date {
|
||||
return new Date(reply);
|
||||
}
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -14,7 +14,7 @@ describe('LCS_LEN', () => {
|
||||
|
||||
testUtils.testAll('lcsLen', async client => {
|
||||
assert.equal(
|
||||
await client.lcsLen('1', '2'),
|
||||
await client.lcsLen('{tag}1', '{tag}2'),
|
||||
0
|
||||
);
|
||||
}, {
|
||||
|
@@ -10,13 +10,10 @@ describe('MOVE', () => {
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testAll('move', async client => {
|
||||
testUtils.testWithClient('client.move', async client => {
|
||||
assert.equal(
|
||||
await client.move('key', 1),
|
||||
0
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './PUBLISH';
|
||||
import PUBLISH from './PUBLISH';
|
||||
|
||||
describe('PUBLISH', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('channel', 'message'),
|
||||
PUBLISH.transformArguments('channel', 'message'),
|
||||
['PUBLISH', 'channel', 'message']
|
||||
);
|
||||
});
|
||||
|
@@ -45,6 +45,11 @@ import DECR from './DECR';
|
||||
import DECRBY from './DECRBY';
|
||||
import DEL from './DEL';
|
||||
import DUMP from './DUMP';
|
||||
import ECHO from './ECHO';
|
||||
import EVAL_RO from './EVAL_RO';
|
||||
import EVAL from './EVAL';
|
||||
import EVALSHA_RO from './EVALSHA_RO';
|
||||
import EVALSHA from './EVALSHA';
|
||||
import GEOADD from './GEOADD';
|
||||
import GEODIST from './GEODIST';
|
||||
import GEOHASH from './GEOHASH';
|
||||
@@ -75,6 +80,7 @@ import EXPIRETIME from './EXPIRETIME';
|
||||
import FLUSHALL from './FLUSHALL';
|
||||
import FLUSHDB from './FLUSHDB';
|
||||
import HDEL from './HDEL';
|
||||
import HELLO from './HELLO';
|
||||
import HEXISTS from './HEXISTS';
|
||||
import HGET from './HGET';
|
||||
import HGETALL from './HGETALL';
|
||||
@@ -96,6 +102,7 @@ import INCRBY from './INCRBY';
|
||||
import INCRBYFLOAT from './INCRBYFLOAT';
|
||||
import INFO from './INFO';
|
||||
import KEYS from './KEYS';
|
||||
import LASTSAVE from './LASTSAVE';
|
||||
// import LCS_IDX_WITHMATCHLEN from './LCS_IDX_WITHMATCHLEN';
|
||||
// import LCS_IDX from './LCS_IDX';
|
||||
import LCS_LEN from './LCS_LEN';
|
||||
@@ -320,6 +327,16 @@ export default {
|
||||
del: DEL,
|
||||
DUMP,
|
||||
dump: DUMP,
|
||||
ECHO,
|
||||
echo: ECHO,
|
||||
EVAL_RO,
|
||||
evalRo: EVAL_RO,
|
||||
EVAL,
|
||||
eval: EVAL,
|
||||
EVALSHA_RO,
|
||||
evalShaRo: EVALSHA_RO,
|
||||
EVALSHA,
|
||||
evalSha: EVALSHA,
|
||||
EXISTS,
|
||||
exists: EXISTS,
|
||||
EXPIRE,
|
||||
@@ -380,6 +397,8 @@ export default {
|
||||
getSet: GETSET,
|
||||
HDEL,
|
||||
hDel: HDEL,
|
||||
HELLO,
|
||||
hello: HELLO,
|
||||
HEXISTS,
|
||||
hExists: HEXISTS,
|
||||
HGET,
|
||||
@@ -422,6 +441,8 @@ export default {
|
||||
info: INFO,
|
||||
KEYS,
|
||||
keys: KEYS,
|
||||
LASTSAVE,
|
||||
lastSave: LASTSAVE,
|
||||
// LCS_IDX_WITHMATCHLEN,
|
||||
// LCS_IDX,
|
||||
LCS_LEN,
|
||||
|
Reference in New Issue
Block a user