You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
some json and search commands
This commit is contained in:
@@ -178,9 +178,8 @@ Some command arguments/replies have changed to align more closely to data types
|
|||||||
- `TOPK.QUERY`: `Array<number>` -> `Array<boolean>`
|
- `TOPK.QUERY`: `Array<number>` -> `Array<boolean>`
|
||||||
- `GRAPH.SLOWLOG`: `timestamp` has been changed from `Date` to `number`
|
- `GRAPH.SLOWLOG`: `timestamp` has been changed from `Date` to `number`
|
||||||
- `JSON.ARRINDEX`: `start` and `end` arguments moved to `{ range: { start: number; end: number; }; }` [^future-proofing]
|
- `JSON.ARRINDEX`: `start` and `end` arguments moved to `{ range: { start: number; end: number; }; }` [^future-proofing]
|
||||||
- `JSON.ARRLEN`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
- `JSON.ARRLEN`, `JSON.CLEAR`, `JSON.DEBUG MEMORY`, `JSON.DEL`, `JSON.FORGET`, `JSON.OBJKEYS`, `JSON.OBJLEN`, `JSON.STRLEN`, `JSON.TYPE`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
||||||
- `JSON.DEL`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
- : `path` argument moved to `{ path: string; }` [^future-proofing]
|
||||||
- `JSON.FORGET`: `path` argument moved to `{ path: string; }` [^future-proofing]
|
|
||||||
- `TS.[M][REV]RANGE`: `enum TimeSeriesBucketTimestamp` -> `const TIME_SERIES_BUCKET_TIMESTAMP` [^enum-to-constants], `enum TimeSeriesReducers` -> `const TIME_SERIES_REDUCERS` [^enum-to-constants], the `ALIGN` argument has been moved into `AGGREGRATION`
|
- `TS.[M][REV]RANGE`: `enum TimeSeriesBucketTimestamp` -> `const TIME_SERIES_BUCKET_TIMESTAMP` [^enum-to-constants], `enum TimeSeriesReducers` -> `const TIME_SERIES_REDUCERS` [^enum-to-constants], the `ALIGN` argument has been moved into `AGGREGRATION`
|
||||||
- `TS.SYNUPDATE`: `Array<string | Array<string>>` -> `Record<string, Array<string>>`
|
- `TS.SYNUPDATE`: `Array<string | Array<string>>` -> `Record<string, Array<string>>`
|
||||||
|
|
||||||
|
@@ -30,11 +30,11 @@ export interface SetOptions {
|
|||||||
|
|
||||||
condition?: 'NX' | 'XX';
|
condition?: 'NX' | 'XX';
|
||||||
/**
|
/**
|
||||||
* @deprecated Use `condition` 'NX' instead
|
* @deprecated Use `{ condition: 'NX' }` instead.
|
||||||
*/
|
*/
|
||||||
NX?: boolean;
|
NX?: boolean;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use `condition` 'XX' instead
|
* @deprecated Use `{ condition: 'XX' }` instead.
|
||||||
*/
|
*/
|
||||||
XX?: boolean;
|
XX?: boolean;
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import DEBUG_MEMORY from './DEBUG_MEMORY';
|
|||||||
|
|
||||||
describe('JSON.DEBUG MEMORY', () => {
|
describe('JSON.DEBUG MEMORY', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
DEBUG_MEMORY.transformArguments('key'),
|
DEBUG_MEMORY.transformArguments('key'),
|
||||||
['JSON.DEBUG', 'MEMORY', 'key']
|
['JSON.DEBUG', 'MEMORY', 'key']
|
||||||
@@ -13,7 +13,9 @@ describe('JSON.DEBUG MEMORY', () => {
|
|||||||
|
|
||||||
it('with path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
DEBUG_MEMORY.transformArguments('key', '$'),
|
DEBUG_MEMORY.transformArguments('key', {
|
||||||
|
path: '$'
|
||||||
|
}),
|
||||||
['JSON.DEBUG', 'MEMORY', 'key', '$']
|
['JSON.DEBUG', 'MEMORY', 'key', '$']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -21,7 +23,7 @@ describe('JSON.DEBUG MEMORY', () => {
|
|||||||
|
|
||||||
testUtils.testWithClient('client.json.debugMemory', async client => {
|
testUtils.testWithClient('client.json.debugMemory', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.json.debugMemory('key', '$'),
|
await client.json.debugMemory('key'),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { RedisArgument, NumberReply, ArrayReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonDebugMemoryOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 2,
|
FIRST_KEY_INDEX: 2,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonDebugMemoryOptions) {
|
||||||
const args = ['JSON.DEBUG', 'MEMORY', key];
|
const args = ['JSON.DEBUG', 'MEMORY', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@@ -4,7 +4,7 @@ import OBJKEYS from './OBJKEYS';
|
|||||||
|
|
||||||
describe('JSON.OBJKEYS', () => {
|
describe('JSON.OBJKEYS', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
OBJKEYS.transformArguments('key'),
|
OBJKEYS.transformArguments('key'),
|
||||||
['JSON.OBJKEYS', 'key']
|
['JSON.OBJKEYS', 'key']
|
||||||
@@ -13,7 +13,9 @@ describe('JSON.OBJKEYS', () => {
|
|||||||
|
|
||||||
it('with path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
OBJKEYS.transformArguments('key', '$'),
|
OBJKEYS.transformArguments('key', {
|
||||||
|
path: '$'
|
||||||
|
}),
|
||||||
['JSON.OBJKEYS', 'key', '$']
|
['JSON.OBJKEYS', 'key', '$']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -21,7 +23,7 @@ describe('JSON.OBJKEYS', () => {
|
|||||||
|
|
||||||
testUtils.testWithClient('client.json.objKeys', async client => {
|
testUtils.testWithClient('client.json.objKeys', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.json.objKeys('key', '$'),
|
await client.json.objKeys('key'),
|
||||||
[null]
|
[null]
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonObjKeysOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonObjKeysOptions) {
|
||||||
const args = ['JSON.OBJKEYS', key];
|
const args = ['JSON.OBJKEYS', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@@ -4,7 +4,7 @@ import OBJLEN from './OBJLEN';
|
|||||||
|
|
||||||
describe('JSON.OBJLEN', () => {
|
describe('JSON.OBJLEN', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
OBJLEN.transformArguments('key'),
|
OBJLEN.transformArguments('key'),
|
||||||
['JSON.OBJLEN', 'key']
|
['JSON.OBJLEN', 'key']
|
||||||
@@ -13,7 +13,9 @@ describe('JSON.OBJLEN', () => {
|
|||||||
|
|
||||||
it('with path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
OBJLEN.transformArguments('key', '$'),
|
OBJLEN.transformArguments('key', {
|
||||||
|
path: '$'
|
||||||
|
}),
|
||||||
['JSON.OBJLEN', 'key', '$']
|
['JSON.OBJLEN', 'key', '$']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -21,8 +23,8 @@ describe('JSON.OBJLEN', () => {
|
|||||||
|
|
||||||
testUtils.testWithClient('client.json.objLen', async client => {
|
testUtils.testWithClient('client.json.objLen', async client => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await client.json.objLen('key', '$'),
|
await client.json.objLen('key'),
|
||||||
[null]
|
null
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonObjLenOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: true,
|
IS_READ_ONLY: true,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonObjLenOptions) {
|
||||||
const args = ['JSON.OBJLEN', key];
|
const args = ['JSON.OBJLEN', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@@ -1,23 +1,34 @@
|
|||||||
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||||
|
|
||||||
export interface NX {
|
export interface JsonSetOptions {
|
||||||
NX: true;
|
condition?: 'NX' | 'XX';
|
||||||
}
|
/**
|
||||||
|
* @deprecated Use `{ condition: 'NX' }` instead.
|
||||||
export interface XX {
|
*/
|
||||||
XX: true;
|
NX?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Use `{ condition: 'XX' }` instead.
|
||||||
|
*/
|
||||||
|
XX?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path: RedisArgument, json: RedisJSON, options?: NX | XX) {
|
transformArguments(
|
||||||
|
key: RedisArgument,
|
||||||
|
path: RedisArgument,
|
||||||
|
json: RedisJSON,
|
||||||
|
options?: JsonSetOptions
|
||||||
|
) {
|
||||||
const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)];
|
const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)];
|
||||||
|
|
||||||
if ((<NX>options)?.NX) {
|
if (options?.condition) {
|
||||||
|
args.push(options?.condition);
|
||||||
|
} else if (options?.NX) {
|
||||||
args.push('NX');
|
args.push('NX');
|
||||||
} else if ((<XX>options)?.XX) {
|
} else if (options?.XX) {
|
||||||
args.push('XX');
|
args.push('XX');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import STRLEN from './STRLEN';
|
|||||||
|
|
||||||
describe('JSON.STRLEN', () => {
|
describe('JSON.STRLEN', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
STRLEN.transformArguments('key'),
|
STRLEN.transformArguments('key'),
|
||||||
['JSON.STRLEN', 'key']
|
['JSON.STRLEN', 'key']
|
||||||
@@ -13,7 +13,9 @@ describe('JSON.STRLEN', () => {
|
|||||||
|
|
||||||
it('with path', () => {
|
it('with path', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
STRLEN.transformArguments('key', '$'),
|
STRLEN.transformArguments('key', {
|
||||||
|
path: '$'
|
||||||
|
}),
|
||||||
['JSON.STRLEN', 'key', '$']
|
['JSON.STRLEN', 'key', '$']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -22,9 +24,9 @@ describe('JSON.STRLEN', () => {
|
|||||||
testUtils.testWithClient('client.json.strLen', async client => {
|
testUtils.testWithClient('client.json.strLen', async client => {
|
||||||
const [, reply] = await Promise.all([
|
const [, reply] = await Promise.all([
|
||||||
client.json.set('key', '$', ''),
|
client.json.set('key', '$', ''),
|
||||||
client.json.strLen('key', '$')
|
client.json.strLen('key')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert.deepEqual(reply, [0]);
|
assert.deepEqual(reply, 0);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
|
export interface JsonStrLenOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: true,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, options?: JsonStrLenOptions) {
|
||||||
const args = ['JSON.STRLEN', key];
|
const args = ['JSON.STRLEN', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@@ -3,20 +3,11 @@ import testUtils, { GLOBAL } from '../test-utils';
|
|||||||
import TOGGLE from './TOGGLE';
|
import TOGGLE from './TOGGLE';
|
||||||
|
|
||||||
describe('JSON.TOGGLE', () => {
|
describe('JSON.TOGGLE', () => {
|
||||||
describe('transformArguments', () => {
|
it('transformArguments', () => {
|
||||||
it('without path', () => {
|
assert.deepEqual(
|
||||||
assert.deepEqual(
|
TOGGLE.transformArguments('key', '$'),
|
||||||
TOGGLE.transformArguments('key'),
|
['JSON.TOGGLE', 'key', '$']
|
||||||
['JSON.TOGGLE', 'key']
|
);
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('with path', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
TOGGLE.transformArguments('key', '$'),
|
|
||||||
['JSON.TOGGLE', 'key', '$']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.json.toggle', async client => {
|
testUtils.testWithClient('client.json.toggle', async client => {
|
||||||
|
@@ -3,14 +3,8 @@ import { RedisArgument, ArrayReply, NumberReply, NullReply, Command, } from '@re
|
|||||||
export default {
|
export default {
|
||||||
FIRST_KEY_INDEX: 1,
|
FIRST_KEY_INDEX: 1,
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
transformArguments(key: RedisArgument, path: RedisArgument) {
|
||||||
const args = ['JSON.TOGGLE', key]
|
return ['JSON.TOGGLE', key, path];
|
||||||
|
|
||||||
if (path) {
|
|
||||||
args.push(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
|
||||||
},
|
},
|
||||||
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
transformReply: undefined as unknown as () => NumberReply | NullReply | ArrayReply<NumberReply | NullReply>
|
||||||
} as const satisfies Command;
|
} as const satisfies Command;
|
||||||
|
@@ -1,28 +1,32 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { transformArguments } from './TYPE';
|
import TYPE from './TYPE';
|
||||||
|
|
||||||
describe('TYPE', () => {
|
describe('TYPE', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without path', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key'),
|
transformArguments('key'),
|
||||||
['JSON.TYPE', 'key']
|
['JSON.TYPE', 'key']
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
it('with path', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
transformArguments('key', '$'),
|
|
||||||
['JSON.TYPE', 'key', '$']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// testUtils.testWithClient('client.json.type', async client => {
|
it('with path', () => {
|
||||||
// assert.deepEqual(
|
assert.deepEqual(
|
||||||
// await client.json.type('key', '$'),
|
transformArguments('key', {
|
||||||
// [null]
|
path: '$'
|
||||||
// );
|
}),
|
||||||
// }, GLOBAL.SERVERS.OPEN);
|
['JSON.TYPE', 'key', '$']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.json.type', async client => {
|
||||||
|
assert.deepEqual(
|
||||||
|
await client.json.type('key', {
|
||||||
|
path: '$'
|
||||||
|
}),
|
||||||
|
[null]
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,13 +1,25 @@
|
|||||||
export const FIRST_KEY_INDEX = 1;
|
import { NullReply, BlobStringReply, ArrayReply, Command, RedisArgument } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
|
||||||
export function transformArguments(key: string, path?: string): Array<string> {
|
export interface JsonTypeOptions {
|
||||||
|
path?: RedisArgument;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
FIRST_KEY_INDEX: 1,
|
||||||
|
IS_READ_ONLY: true,
|
||||||
|
transformArguments(key: RedisArgument, options?: JsonTypeOptions) {
|
||||||
const args = ['JSON.TYPE', key];
|
const args = ['JSON.TYPE', key];
|
||||||
|
|
||||||
if (path) {
|
if (options?.path) {
|
||||||
args.push(path);
|
args.push(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
},
|
||||||
|
transformReply: {
|
||||||
|
2: undefined as unknown as () => NullReply | BlobStringReply | ArrayReply<BlobStringReply>,
|
||||||
|
// TODO: ?!??!
|
||||||
|
3: undefined as unknown as () => any
|
||||||
|
}
|
||||||
|
} as const satisfies Command;
|
||||||
|
|
||||||
export declare function transformReply(): string | null | Array<string | null>;
|
|
||||||
|
@@ -19,7 +19,7 @@ import SET from './SET';
|
|||||||
import STRAPPEND from './STRAPPEND';
|
import STRAPPEND from './STRAPPEND';
|
||||||
import STRLEN from './STRLEN';
|
import STRLEN from './STRLEN';
|
||||||
import TOGGLE from './TOGGLE';
|
import TOGGLE from './TOGGLE';
|
||||||
// import TYPE from './TYPE';
|
import TYPE from './TYPE';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ARRAPPEND,
|
ARRAPPEND,
|
||||||
@@ -64,8 +64,8 @@ export default {
|
|||||||
strLen: STRLEN,
|
strLen: STRLEN,
|
||||||
TOGGLE,
|
TOGGLE,
|
||||||
toggle: TOGGLE,
|
toggle: TOGGLE,
|
||||||
// TYPE,
|
TYPE,
|
||||||
// type: TYPE
|
type: TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||||
|
@@ -1,37 +1,35 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { transformArguments } from './ALTER';
|
import ALTER from './ALTER';
|
||||||
import { SchemaFieldTypes } from '.';
|
import { SCHEMA_FIELD_TYPE } from './CREATE';
|
||||||
|
|
||||||
describe('ALTER', () => {
|
describe('FT.ALTER', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('with NOINDEX', () => {
|
it('with NOINDEX', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('index', {
|
ALTER.transformArguments('index', {
|
||||||
field: {
|
field: {
|
||||||
type: SchemaFieldTypes.TEXT,
|
type: SCHEMA_FIELD_TYPE.TEXT,
|
||||||
NOINDEX: true,
|
NOINDEX: true,
|
||||||
SORTABLE: 'UNF',
|
SORTABLE: 'UNF',
|
||||||
AS: 'text'
|
AS: 'text'
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
['FT.ALTER', 'index', 'SCHEMA', 'ADD', 'field', 'AS', 'text', 'TEXT', 'SORTABLE', 'UNF', 'NOINDEX']
|
['FT.ALTER', 'index', 'SCHEMA', 'ADD', 'field', 'AS', 'text', 'TEXT', 'SORTABLE', 'UNF', 'NOINDEX']
|
||||||
);
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.ft.create', async client => {
|
testUtils.testWithClient('client.ft.create', async client => {
|
||||||
await Promise.all([
|
const [, reply] = await Promise.all([
|
||||||
client.ft.create('index', {
|
client.ft.create('index', {
|
||||||
title: SchemaFieldTypes.TEXT
|
title: SCHEMA_FIELD_TYPE.TEXT
|
||||||
}),
|
}),
|
||||||
]);
|
client.ft.alter('index', {
|
||||||
|
body: SCHEMA_FIELD_TYPE.TEXT
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(reply, 'OK');
|
||||||
await client.ft.alter('index', {
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
body: SchemaFieldTypes.TEXT
|
|
||||||
}),
|
|
||||||
'OK'
|
|
||||||
);
|
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
|
||||||
});
|
});
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
import { RediSearchSchema, pushSchema } from '.';
|
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
|
import { RediSearchSchema, pushSchema } from './CREATE';
|
||||||
|
|
||||||
export function transformArguments(index: string, schema: RediSearchSchema): Array<string> {
|
export default {
|
||||||
|
FIRST_KEY_INDEX: undefined,
|
||||||
|
IS_READ_ONLY: true,
|
||||||
|
transformArguments(index: RedisArgument, schema: RediSearchSchema) {
|
||||||
const args = ['FT.ALTER', index, 'SCHEMA', 'ADD'];
|
const args = ['FT.ALTER', index, 'SCHEMA', 'ADD'];
|
||||||
pushSchema(args, schema);
|
pushSchema(args, schema);
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
},
|
||||||
|
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||||
export declare function transformReply(): 'OK';
|
} as const satisfies Command;
|
||||||
|
@@ -1,12 +1,19 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { transformArguments } from './CONFIG_SET';
|
import CONFIG_SET from './CONFIG_SET';
|
||||||
|
|
||||||
describe('CONFIG SET', () => {
|
describe('FT.CONFIG SET', () => {
|
||||||
it('transformArguments', () => {
|
it('transformArguments', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('TIMEOUT', '500'),
|
CONFIG_SET.transformArguments('TIMEOUT', '500'),
|
||||||
['FT.CONFIG', 'SET', 'TIMEOUT', '500']
|
['FT.CONFIG', 'SET', 'TIMEOUT', '500']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ft.configSet', async client => {
|
||||||
|
assert.deepEqual(
|
||||||
|
await client.ft.configSet('TIMEOUT', '500'),
|
||||||
|
'OK'
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,14 @@
|
|||||||
export function transformArguments(option: string, value: string): Array<string> {
|
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
return ['FT.CONFIG', 'SET', option, value];
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare function transformReply(): 'OK';
|
// using `string & {}` to avoid TS widening the type to `string`
|
||||||
|
// TODO
|
||||||
|
type FtConfigProperties = 'a' | 'b' | (string & {}) | Buffer;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
FIRST_KEY_INDEX: undefined,
|
||||||
|
IS_READ_ONLY: true,
|
||||||
|
transformArguments(property: FtConfigProperties, value: RedisArgument) {
|
||||||
|
return ['FT.CONFIG', 'SET', property, value];
|
||||||
|
},
|
||||||
|
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||||
|
} as const satisfies Command;
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
import _LIST from './_LIST';
|
import _LIST from './_LIST';
|
||||||
// import ALTER from './ALTER';
|
import ALTER from './ALTER';
|
||||||
// import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
|
// import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
|
||||||
// import AGGREGATE from './AGGREGATE';
|
// import AGGREGATE from './AGGREGATE';
|
||||||
import ALIASADD from './ALIASADD';
|
import ALIASADD from './ALIASADD';
|
||||||
import ALIASDEL from './ALIASDEL';
|
import ALIASDEL from './ALIASDEL';
|
||||||
import ALIASUPDATE from './ALIASUPDATE';
|
import ALIASUPDATE from './ALIASUPDATE';
|
||||||
// import CONFIG_GET from './CONFIG_GET';
|
// import CONFIG_GET from './CONFIG_GET';
|
||||||
// import CONFIG_SET from './CONFIG_SET';
|
import CONFIG_SET from './CONFIG_SET';
|
||||||
import CREATE from './CREATE';
|
import CREATE from './CREATE';
|
||||||
import CURSOR_DEL from './CURSOR_DEL';
|
import CURSOR_DEL from './CURSOR_DEL';
|
||||||
// import CURSOR_READ from './CURSOR_READ';
|
// import CURSOR_READ from './CURSOR_READ';
|
||||||
@@ -39,8 +39,8 @@ import { CommandArguments } from '@redis/client/dist/lib/RESP/types';
|
|||||||
export default {
|
export default {
|
||||||
_LIST,
|
_LIST,
|
||||||
_list: _LIST,
|
_list: _LIST,
|
||||||
// ALTER,
|
ALTER,
|
||||||
// alter: ALTER,
|
alter: ALTER,
|
||||||
// AGGREGATE_WITHCURSOR,
|
// AGGREGATE_WITHCURSOR,
|
||||||
// aggregateWithCursor: AGGREGATE_WITHCURSOR,
|
// aggregateWithCursor: AGGREGATE_WITHCURSOR,
|
||||||
// AGGREGATE,
|
// AGGREGATE,
|
||||||
@@ -53,8 +53,8 @@ export default {
|
|||||||
aliasUpdate: ALIASUPDATE,
|
aliasUpdate: ALIASUPDATE,
|
||||||
// CONFIG_GET,
|
// CONFIG_GET,
|
||||||
// configGet: CONFIG_GET,
|
// configGet: CONFIG_GET,
|
||||||
// CONFIG_SET,
|
CONFIG_SET,
|
||||||
// configSet: CONFIG_SET,
|
configSet: CONFIG_SET,
|
||||||
CREATE,
|
CREATE,
|
||||||
create: CREATE,
|
create: CREATE,
|
||||||
CURSOR_DEL,
|
CURSOR_DEL,
|
||||||
|
Reference in New Issue
Block a user