1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
* init

* implement graph commands

* add graph to packages table

* fix ts.infoDebug

* fix redisearch tests

* Update INFO_DEBUG.ts

* fix INFO.spec.ts

* test QUERY and SLOWLOG

Co-authored-by: Avital-Fine <avital.fine@redis.com>
This commit is contained in:
Leibale Eidelman
2022-01-31 12:52:19 -05:00
committed by GitHub
parent 46b831c922
commit 3547b20293
46 changed files with 563 additions and 39 deletions

View File

@@ -0,0 +1,4 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"exclude": ["**/*.spec.ts", "lib/test-utils.ts"]
}

View File

@@ -0,0 +1,10 @@
{
"git": {
"tagName": "graph@${version}",
"commitMessage": "Release ${tagName}",
"tagAnnotation": "Release ${tagName}"
},
"npm": {
"publishArgs": ["--access", "public"]
}
}

1
packages/graph/README.md Normal file
View File

@@ -0,0 +1 @@
# @node-redis/graph

View File

@@ -0,0 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CONFIG_GET';
describe('CONFIG GET', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('TIMEOUT'),
['GRAPH.CONFIG', 'GET', 'TIMEOUT']
);
});
testUtils.testWithClient('client.graph.configGet', async client => {
assert.deepEqual(
await client.graph.configGet('TIMEOUT'),
[
'TIMEOUT',
0
]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,12 @@
export const IS_READ_ONLY = true;
export function transformArguments(configKey: string): Array<string> {
return ['GRAPH.CONFIG', 'GET', configKey];
}
type ConfigItem = [
configKey: string,
value: number
];
export declare function transformReply(): ConfigItem | Array<ConfigItem>;

View File

@@ -0,0 +1,19 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CONFIG_SET';
describe('CONFIG SET', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('TIMEOUT', 0),
['GRAPH.CONFIG', 'SET', 'TIMEOUT', '0']
);
});
testUtils.testWithClient('client.graph.configSet', async client => {
assert.equal(
await client.graph.configSet('TIMEOUT', 0),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,10 @@
export function transformArguments(configKey: string, value: number): Array<string> {
return [
'GRAPH.CONFIG',
'SET',
configKey,
value.toString()
];
}
export declare function transformReply(): 'OK';

View File

@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DELETE';
describe('', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['GRAPH.DELETE', 'key']
);
});
testUtils.testWithClient('client.graph.delete', async client => {
await client.graph.query('key', 'RETURN 1');
assert.equal(
typeof await client.graph.delete('key'),
'string'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,7 @@
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string): Array<string> {
return ['GRAPH.DELETE', key];
}
export declare function transformReply(): string;

View File

@@ -0,0 +1,18 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './EXPLAIN';
describe('EXPLAIN', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'RETURN 0'),
['GRAPH.EXPLAIN', 'key', 'RETURN 0']
);
});
testUtils.testWithClient('client.graph.explain', async client => {
const reply = await client.graph.explain('key', 'RETURN 0');
assert.ok(Array.isArray(reply));
assert.ok(!reply.find(x => typeof x !== 'string'));
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,9 @@
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(key: string, query: string): Array<string> {
return ['GRAPH.EXPLAIN', key, query];
}
export declare function transfromReply(): Array<string>;

View File

@@ -0,0 +1,19 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './LIST';
describe('LIST', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments(),
['GRAPH.LIST']
);
});
testUtils.testWithClient('client.graph.list', async client => {
assert.deepEqual(
await client.graph.list(),
[]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,7 @@
export const IS_READ_ONLY = true;
export function transformArguments(): Array<string> {
return ['GRAPH.LIST'];
}
export declare function transformReply(): Array<string>;

View File

@@ -0,0 +1,18 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PROFILE';
describe('PROFILE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'RETURN 0'),
['GRAPH.PROFILE', 'key', 'RETURN 0']
);
});
testUtils.testWithClient('client.graph.profile', async client => {
const reply = await client.graph.profile('key', 'RETURN 0');
assert.ok(Array.isArray(reply));
assert.ok(!reply.find(x => typeof x !== 'string'));
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,9 @@
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(key: string, query: string): Array<string> {
return ['GRAPH.PROFILE', key, query];
}
export declare function transfromReply(): Array<string>;

View File

@@ -0,0 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './QUERY';
describe('QUERY', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', '*', 100),
['GRAPH.QUERY', 'key', '*', '100']
);
});
testUtils.testWithClient('client.graph.query', async client => {
await client.graph.query('key',
"CREATE (r:human {name:'roi', age:34}), (a:human {name:'amit', age:32}), (r)-[:knows]->(a)"
);
const reply = await client.graph.query('key',
"MATCH (r:human)-[:knows]->(a:human) RETURN r.age, r.name"
);
assert.equal(reply.data.length, 1);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,43 @@
import { RedisCommandArgument, RedisCommandArguments } from '@node-redis/client/dist/lib/commands/index';
import { pushQueryArguments } from '.';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(
graph: RedisCommandArgument,
query: RedisCommandArgument,
timeout?: number
): RedisCommandArguments {
return pushQueryArguments(
['GRAPH.QUERY'],
graph,
query,
timeout
);
}
type Headers = Array<string>;
type Data = Array<Array<string | number | null>>;
type Metadata = Array<string>;
type QueryRawReply = [
headers: Headers,
data: Data,
metadata: Metadata
];
interface QueryReply {
headers: Headers,
data: Data,
metadata: Metadata
};
export function transformReply(reply: QueryRawReply): QueryReply {
return {
headers: reply[0],
data: reply[1],
metadata: reply[2]
};
}

View File

@@ -0,0 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './QUERY_RO';
describe('QUERY_RO', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', '*', 100),
['GRAPH.RO_QUERY', 'key', '*', '100']
);
});
testUtils.testWithClient('client.graph.queryRo', async client => {
await client.graph.query('key',
"CREATE (r:human {name:'roi', age:34}), (a:human {name:'amit', age:32}), (r)-[:knows]->(a)"
);
const reply = await client.graph.queryRo('key',
"MATCH (r:human)-[:knows]->(a:human) RETURN r.age, r.name"
);
assert.equal(reply.data.length, 1);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,21 @@
import { RedisCommandArgument, RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
import { pushQueryArguments } from '.';
export { FIRST_KEY_INDEX } from './QUERY';
export const IS_READ_ONLY = true;
export function transformArguments(
graph: RedisCommandArgument,
query: RedisCommandArgument,
timeout?: number
): RedisCommandArguments {
return pushQueryArguments(
['GRAPH.RO_QUERY'],
graph,
query,
timeout
);
}
export { transformReply } from './QUERY';

View File

@@ -0,0 +1,18 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SLOWLOG';
describe('SLOWLOG', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['GRAPH.SLOWLOG', 'key']
);
});
testUtils.testWithClient('client.graph.slowLog', async client => {
await client.graph.query('key', 'RETURN 1');
const reply = await client.graph.slowLog('key');
assert.equal(reply.length, 1);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -0,0 +1,30 @@
export const IS_READ_ONLY = true;
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string) {
return ['GRAPH.SLOWLOG', key];
}
type SlowLogRawReply = Array<[
timestamp: string,
command: string,
query: string,
took: string
]>;
type SlowLogReply = Array<{
timestamp: Date;
command: string;
query: string;
took: number;
}>;
export function transformReply(logs: SlowLogRawReply): SlowLogReply {
return logs.map(([timestamp, command, query, took]) => ({
timestamp: new Date(Number(timestamp) * 1000),
command,
query,
took: Number(took)
}));
}

View File

@@ -0,0 +1,49 @@
import * as CONFIG_GET from './CONFIG_GET';
import * as CONFIG_SET from './CONFIG_SET';;
import * as DELETE from './DELETE';
import * as EXPLAIN from './EXPLAIN';
import * as LIST from './LIST';
import * as PROFILE from './PROFILE';
import * as QUERY_RO from './QUERY_RO';
import * as QUERY from './QUERY';
import * as SLOWLOG from './SLOWLOG';
import { RedisCommandArgument, RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
export default {
CONFIG_GET,
configGet: CONFIG_GET,
CONFIG_SET,
configSet: CONFIG_SET,
DELETE,
delete: DELETE,
EXPLAIN,
explain: EXPLAIN,
LIST,
list: LIST,
PROFILE,
profile: PROFILE,
QUERY_RO,
queryRo: QUERY_RO,
QUERY,
query: QUERY,
SLOWLOG,
slowLog: SLOWLOG
};
export function pushQueryArguments(
args: RedisCommandArguments,
graph: RedisCommandArgument,
query: RedisCommandArgument,
timeout?: number
): RedisCommandArguments {
args.push(
graph,
query
);
if (timeout !== undefined) {
args.push(timeout.toString());
}
return args;
}

View File

@@ -0,0 +1 @@
export { default } from './commands';

View File

@@ -0,0 +1,21 @@
import TestUtils from '@node-redis/test-utils';
import RedisGraph from '.';
export default new TestUtils({
dockerImageName: 'redislabs/redisgraph',
dockerImageVersionArgument: 'redisgraph-version',
defaultDockerVersion: '2.8.7'
});
export const GLOBAL = {
SERVERS: {
OPEN: {
serverArguments: ['--loadmodule /usr/lib/redis/modules/redisgraph.so'],
clientOptions: {
modules: {
graph: RedisGraph
}
}
}
}
};

View File

@@ -0,0 +1,29 @@
{
"name": "@node-redis/graph",
"version": "1.0.0-rc",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/"
],
"scripts": {
"test": "nyc -r text-summary -r lcov mocha -r source-map-support/register -r ts-node/register './lib/**/*.spec.ts'",
"build": "tsc",
"documentation": "typedoc"
},
"peerDependencies": {
"@node-redis/client": "^1.0.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@node-redis/test-utils": "*",
"@types/node": "^17.0.13",
"nyc": "^15.1.0",
"release-it": "^14.12.4",
"source-map-support": "^0.5.21",
"ts-node": "^10.4.0",
"typedoc": "^0.22.11",
"typescript": "^4.5.5"
}
}

View File

@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": [
"./lib/**/*.ts"
],
"exclude": [
"./lib/test-utils.ts",
"./lib/**/*.spec.ts"
],
"typedocOptions": {
"entryPoints": [
"./lib"
],
"entryPointStrategy": "expand",
"out": "../../documentation/graph"
}
}