You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
cluster
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
|
@@ -11,10 +11,11 @@ describe('CLUSTER REPLICAS', () => {
|
||||
});
|
||||
|
||||
testUtils.testWithCluster('clusterNode.clusterReplicas', async cluster => {
|
||||
const client = await cluster.nodeClient(cluster.masters[0]);
|
||||
assert.equal(
|
||||
typeof await client.clusterReplicas(cluster.masters[0].id),
|
||||
'string'
|
||||
);
|
||||
const client = await cluster.nodeClient(cluster.masters[0]),
|
||||
reply = await client.clusterReplicas(cluster.masters[0].id);
|
||||
assert.ok(Array.isArray(reply));
|
||||
for (const replica of reply) {
|
||||
assert.equal(typeof replica, 'string');
|
||||
}
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
});
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { RedisArgument, VerbatimStringReply, Command } from '../RESP/types';
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
@@ -6,5 +6,5 @@ export default {
|
||||
transformArguments(nodeId: RedisArgument) {
|
||||
return ['CLUSTER', 'REPLICAS', nodeId];
|
||||
},
|
||||
transformReply: undefined as unknown as () => VerbatimStringReply
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -21,7 +21,7 @@ describe('FCALL', () => {
|
||||
loadMathFunction(client),
|
||||
client.set('key', '2'),
|
||||
client.fCall(MATH_FUNCTION.library.square.NAME, {
|
||||
arguments: ['key']
|
||||
keys: ['key']
|
||||
})
|
||||
]);
|
||||
|
||||
|
@@ -21,7 +21,7 @@ describe('FCALL_RO', () => {
|
||||
loadMathFunction(client),
|
||||
client.set('key', '2'),
|
||||
client.fCallRo(MATH_FUNCTION.library.square.NAME, {
|
||||
arguments: ['key']
|
||||
keys: ['key']
|
||||
})
|
||||
]);
|
||||
|
||||
|
@@ -4,6 +4,8 @@ import FUNCTION_LOAD from './FUNCTION_LOAD';
|
||||
import { RedisClientType } from '../client';
|
||||
import { NumberReply, RedisFunctions, RedisModules, RedisScripts, RespVersions } from '../RESP/types';
|
||||
|
||||
|
||||
|
||||
export const MATH_FUNCTION = {
|
||||
name: 'math',
|
||||
engine: 'LUA',
|
||||
@@ -11,10 +13,10 @@ export const MATH_FUNCTION = {
|
||||
`#!LUA name=math
|
||||
redis.register_function {
|
||||
function_name = "square",
|
||||
callback = function(keys, args) {
|
||||
callback = function(keys, args)
|
||||
local number = redis.call('GET', keys[1])
|
||||
return number * number
|
||||
},
|
||||
end,
|
||||
flags = { "no-writes" }
|
||||
}`,
|
||||
library: {
|
||||
|
@@ -1,76 +1,76 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { transformArguments } from './MIGRATE';
|
||||
import MIGRATE from './MIGRATE';
|
||||
|
||||
describe('MIGRATE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single key', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, 'key', 0, 10),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple keys', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, ['1', '2'], 0, 10),
|
||||
['MIGRATE', '127.0.0.1', '6379', '', '0', '10', 'KEYS', '1', '2']
|
||||
);
|
||||
});
|
||||
|
||||
it('with COPY', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
COPY: true
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'COPY']
|
||||
);
|
||||
});
|
||||
|
||||
it('with REPLACE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
REPLACE: true
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'REPLACE']
|
||||
);
|
||||
});
|
||||
|
||||
describe('with AUTH', () => {
|
||||
it('password only', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
AUTH: {
|
||||
password: 'password'
|
||||
}
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'AUTH', 'password']
|
||||
);
|
||||
});
|
||||
|
||||
it('username & password', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
AUTH: {
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
}
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'AUTH2', 'username', 'password']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('with COPY, REPLACE, AUTH', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
COPY: true,
|
||||
REPLACE: true,
|
||||
AUTH: {
|
||||
password: 'password'
|
||||
}
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'COPY', 'REPLACE', 'AUTH', 'password']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('single key', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, 'key', 0, 10),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple keys', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, ['1', '2'], 0, 10),
|
||||
['MIGRATE', '127.0.0.1', '6379', '', '0', '10', 'KEYS', '1', '2']
|
||||
);
|
||||
});
|
||||
|
||||
it('with COPY', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
COPY: true
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'COPY']
|
||||
);
|
||||
});
|
||||
|
||||
it('with REPLACE', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
REPLACE: true
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'REPLACE']
|
||||
);
|
||||
});
|
||||
|
||||
describe('with AUTH', () => {
|
||||
it('password only', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
AUTH: {
|
||||
password: 'password'
|
||||
}
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'AUTH', 'password']
|
||||
);
|
||||
});
|
||||
|
||||
it('username & password', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
AUTH: {
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
}
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'AUTH2', 'username', 'password']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('with COPY, REPLACE, AUTH', () => {
|
||||
assert.deepEqual(
|
||||
MIGRATE.transformArguments('127.0.0.1', 6379, 'key', 0, 10, {
|
||||
COPY: true,
|
||||
REPLACE: true,
|
||||
AUTH: {
|
||||
password: 'password'
|
||||
}
|
||||
}),
|
||||
['MIGRATE', '127.0.0.1', '6379', 'key', '0', '10', 'COPY', 'REPLACE', 'AUTH', 'password']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,13 +1,14 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
import { AuthOptions } from './AUTH';
|
||||
|
||||
interface MigrateOptions {
|
||||
export interface MigrateOptions {
|
||||
COPY?: true;
|
||||
REPLACE?: true;
|
||||
AUTH?: AuthOptions;
|
||||
}
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
host: RedisArgument,
|
||||
port: number,
|
||||
@@ -62,5 +63,5 @@ export default {
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, newKey: RedisArgument) {
|
||||
return ['RENAME', key, newKey];
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, newKey: RedisArgument) {
|
||||
return ['RENAMENX', key, newKey];
|
||||
|
@@ -2,7 +2,7 @@ import { RedisArgument, Command } from '../RESP/types';
|
||||
import { transformSortedSetReply } from './generic-transformers';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, count: number) {
|
||||
return ['ZPOPMAX', key, count.toString()];
|
||||
|
@@ -184,6 +184,7 @@ import MEMORY_PURGE from './MEMORY_PURGE';
|
||||
import MEMORY_STATS from './MEMORY_STATS';
|
||||
import MEMORY_USAGE from './MEMORY_USAGE';
|
||||
import MGET from './MGET';
|
||||
import MIGRATE from './MIGRATE';
|
||||
import MODULE_LIST from './MODULE_LIST';
|
||||
import MODULE_LOAD from './MODULE_LOAD';
|
||||
import MODULE_UNLOAD from './MODULE_UNLOAD';
|
||||
@@ -703,6 +704,8 @@ export default {
|
||||
memoryUsage: MEMORY_USAGE,
|
||||
MGET,
|
||||
mGet: MGET,
|
||||
MIGRATE,
|
||||
migrate: MIGRATE,
|
||||
MODULE_LIST,
|
||||
moduleList: MODULE_LIST,
|
||||
MODULE_LOAD,
|
||||
|
Reference in New Issue
Block a user