You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
WIP
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './ACL_CAT';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ACL_CAT from './ACL_CAT';
|
||||
|
||||
describe('ACL CAT', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'CAT']
|
||||
);
|
||||
});
|
||||
|
||||
it('with categoryName', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('dangerous'),
|
||||
['ACL', 'CAT', 'dangerous']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ACL_CAT.transformArguments(),
|
||||
['ACL', 'CAT']
|
||||
);
|
||||
});
|
||||
|
||||
it('with categoryName', () => {
|
||||
assert.deepEqual(
|
||||
ACL_CAT.transformArguments('dangerous'),
|
||||
['ACL', 'CAT', 'dangerous']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclCat', async client => {
|
||||
const categories = await client.aclCat();
|
||||
assert.ok(Array.isArray(categories));
|
||||
for (const category of categories) {
|
||||
assert.equal(typeof category, 'string');
|
||||
}
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,13 +1,16 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(categoryName?: RedisCommandArgument): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = ['ACL', 'CAT'];
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(categoryName?: RedisArgument) {
|
||||
const args: Array<RedisArgument> = ['ACL', 'CAT'];
|
||||
|
||||
if (categoryName) {
|
||||
args.push(categoryName);
|
||||
args.push(categoryName);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,30 +1,30 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ACL_DELUSER';
|
||||
import ACL_DELUSER from './ACL_DELUSER';
|
||||
|
||||
describe('ACL DELUSER', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('string', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('username'),
|
||||
['ACL', 'DELUSER', 'username']
|
||||
);
|
||||
});
|
||||
|
||||
it('array', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(['1', '2']),
|
||||
['ACL', 'DELUSER', '1', '2']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('string', () => {
|
||||
assert.deepEqual(
|
||||
ACL_DELUSER.transformArguments('username'),
|
||||
['ACL', 'DELUSER', 'username']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclDelUser', async client => {
|
||||
assert.equal(
|
||||
await client.aclDelUser('dosenotexists'),
|
||||
0
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
it('array', () => {
|
||||
assert.deepEqual(
|
||||
ACL_DELUSER.transformArguments(['1', '2']),
|
||||
['ACL', 'DELUSER', '1', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclDelUser', async client => {
|
||||
assert.equal(
|
||||
typeof await client.aclDelUser('user'),
|
||||
'number'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { NumberReply, Command } from '../RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export function transformArguments(
|
||||
username: RedisCommandArgument | Array<RedisCommandArgument>
|
||||
): RedisCommandArguments {
|
||||
return pushVerdictArguments(['ACL', 'DELUSER'], username);
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(username: RedisVariadicArgument) {
|
||||
return pushVariadicArguments(['ACL', 'DELUSER'], username);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,21 +1,21 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ACL_DRYRUN';
|
||||
import ACL_DRYRUN from './ACL_DRYRUN';
|
||||
|
||||
describe('ACL DRYRUN', () => {
|
||||
testUtils.isVersionGreaterThanHook([7]);
|
||||
testUtils.isVersionGreaterThanHook([7]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('default', ['GET', 'key']),
|
||||
['ACL', 'DRYRUN', 'default', 'GET', 'key']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ACL_DRYRUN.transformArguments('default', ['GET', 'key']),
|
||||
['ACL', 'DRYRUN', 'default', 'GET', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclDryRun', async client => {
|
||||
assert.equal(
|
||||
await client.aclDryRun('default', ['GET', 'key']),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
testUtils.testWithClient('client.aclDryRun', async client => {
|
||||
assert.equal(
|
||||
await client.aclDryRun('default', ['GET', 'key']),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,18 +1,16 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, SimpleStringReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
username: RedisCommandArgument,
|
||||
command: Array<RedisCommandArgument>
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(username: RedisArgument, command: Array<RedisArgument>) {
|
||||
return [
|
||||
'ACL',
|
||||
'DRYRUN',
|
||||
username,
|
||||
...command
|
||||
'ACL',
|
||||
'DRYRUN',
|
||||
username,
|
||||
...command
|
||||
];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'> | BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
||||
|
@@ -1,23 +1,30 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './ACL_GENPASS';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ACL_GENPASS from './ACL_GENPASS';
|
||||
|
||||
describe('ACL GENPASS', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'GENPASS']
|
||||
);
|
||||
});
|
||||
|
||||
it('with bits', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(128),
|
||||
['ACL', 'GENPASS', '128']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ACL_GENPASS.transformArguments(),
|
||||
['ACL', 'GENPASS']
|
||||
);
|
||||
});
|
||||
|
||||
it('with bits', () => {
|
||||
assert.deepEqual(
|
||||
ACL_GENPASS.transformArguments(128),
|
||||
['ACL', 'GENPASS', '128']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclGenPass', async client => {
|
||||
assert.equal(
|
||||
typeof await client.aclGenPass(),
|
||||
'string'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(bits?: number): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(bits?: number) {
|
||||
const args = ['ACL', 'GENPASS'];
|
||||
|
||||
if (bits) {
|
||||
args.push(bits.toString());
|
||||
args.push(bits.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
|
@@ -1,44 +1,34 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ACL_GETUSER';
|
||||
import ACL_GETUSER from './ACL_GETUSER';
|
||||
|
||||
describe('ACL GETUSER', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('username'),
|
||||
['ACL', 'GETUSER', 'username']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ACL_GETUSER.transformArguments('username'),
|
||||
['ACL', 'GETUSER', 'username']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclGetUser', async client => {
|
||||
const expectedReply: any = {
|
||||
passwords: [],
|
||||
commands: '+@all',
|
||||
};
|
||||
testUtils.testWithClient('client.aclGetUser', async client => {
|
||||
const reply = await client.aclGetUser('default');
|
||||
|
||||
if (testUtils.isVersionGreaterThan([7])) {
|
||||
expectedReply.flags = ['on', 'nopass'];
|
||||
expectedReply.keys = '~*';
|
||||
expectedReply.channels = '&*';
|
||||
expectedReply.selectors = [];
|
||||
} else {
|
||||
expectedReply.keys = ['*'];
|
||||
expectedReply.selectors = undefined;
|
||||
assert.ok(Array.isArray(reply.passwords));
|
||||
assert.equal(typeof reply.commands, 'string');
|
||||
assert.ok(Array.isArray(reply.flags));
|
||||
|
||||
if (testUtils.isVersionGreaterThan([6, 2])) {
|
||||
expectedReply.flags = ['on', 'allkeys', 'allchannels', 'allcommands', 'nopass'];
|
||||
expectedReply.channels = ['*'];
|
||||
} else {
|
||||
expectedReply.flags = ['on', 'allkeys', 'allcommands', 'nopass'];
|
||||
expectedReply.channels = undefined;
|
||||
}
|
||||
}
|
||||
if (testUtils.isVersionGreaterThan([7])) {
|
||||
assert.equal(typeof reply.keys, 'string');
|
||||
assert.equal(typeof reply.channels, 'string');
|
||||
assert.ok(Array.isArray(reply.selectors));
|
||||
} else {
|
||||
assert.ok(Array.isArray(reply.keys));
|
||||
|
||||
assert.deepEqual(
|
||||
await client.aclGetUser('default'),
|
||||
expectedReply
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
if (testUtils.isVersionGreaterThan([6, 2])) {
|
||||
assert.ok(Array.isArray(reply.channels));
|
||||
}
|
||||
}
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,40 +1,40 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, TuplesToMapReply, BlobStringReply, ArrayReply, Resp2Reply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(username: RedisCommandArgument): RedisCommandArguments {
|
||||
type AclUser = TuplesToMapReply<[
|
||||
[BlobStringReply<'flags'>, ArrayReply<BlobStringReply>],
|
||||
[BlobStringReply<'passwords'>, ArrayReply<BlobStringReply>],
|
||||
[BlobStringReply<'commands'>, BlobStringReply],
|
||||
/** changed to BlobStringReply in 7.0 */
|
||||
[BlobStringReply<'keys'>, ArrayReply<BlobStringReply> | BlobStringReply],
|
||||
/** added in 6.2, changed to BlobStringReply in 7.0 */
|
||||
[BlobStringReply<'channels'>, ArrayReply<BlobStringReply> | BlobStringReply],
|
||||
/** added in 7.0 */
|
||||
[BlobStringReply<'selectors'>, ArrayReply<TuplesToMapReply<[
|
||||
[BlobStringReply<'commands'>, BlobStringReply],
|
||||
[BlobStringReply<'keys'>, BlobStringReply],
|
||||
[BlobStringReply<'channels'>, BlobStringReply]
|
||||
]>>],
|
||||
]>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(username: RedisArgument) {
|
||||
return ['ACL', 'GETUSER', username];
|
||||
}
|
||||
|
||||
type AclGetUserRawReply = [
|
||||
'flags',
|
||||
Array<RedisCommandArgument>,
|
||||
'passwords',
|
||||
Array<RedisCommandArgument>,
|
||||
'commands',
|
||||
RedisCommandArgument,
|
||||
'keys',
|
||||
Array<RedisCommandArgument> | RedisCommandArgument,
|
||||
'channels',
|
||||
Array<RedisCommandArgument> | RedisCommandArgument,
|
||||
'selectors' | undefined,
|
||||
Array<Array<string>> | undefined
|
||||
];
|
||||
|
||||
interface AclUser {
|
||||
flags: Array<RedisCommandArgument>;
|
||||
passwords: Array<RedisCommandArgument>;
|
||||
commands: RedisCommandArgument;
|
||||
keys: Array<RedisCommandArgument> | RedisCommandArgument;
|
||||
channels: Array<RedisCommandArgument> | RedisCommandArgument;
|
||||
selectors?: Array<Array<string>>;
|
||||
}
|
||||
|
||||
export function transformReply(reply: AclGetUserRawReply): AclUser {
|
||||
return {
|
||||
flags: reply[1],
|
||||
passwords: reply[3],
|
||||
commands: reply[5],
|
||||
keys: reply[7],
|
||||
channels: reply[9],
|
||||
selectors: reply[11]
|
||||
};
|
||||
}
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: Resp2Reply<AclUser>) => ({
|
||||
flags: reply[1],
|
||||
passwords: reply[3],
|
||||
commands: reply[5],
|
||||
keys: reply[7],
|
||||
channels: reply[9],
|
||||
selectors: reply[11]?.map(selector => ({
|
||||
commands: selector[1],
|
||||
keys: selector[3],
|
||||
channels: selector[5]
|
||||
}))
|
||||
}),
|
||||
3: undefined as unknown as () => AclUser
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,14 +1,22 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './ACL_LIST';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ACL_LIST from './ACL_LIST';
|
||||
|
||||
describe('ACL LIST', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'LIST']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ACL_LIST.transformArguments(),
|
||||
['ACL', 'LIST']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclList', async client => {
|
||||
const users = await client.aclList();
|
||||
assert.ok(Array.isArray(users));
|
||||
for (const user of users) {
|
||||
assert.equal(typeof user, 'string');
|
||||
}
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['ACL', 'LIST'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './ACL_SAVE';
|
||||
import ACL_LOAD from './ACL_LOAD';
|
||||
|
||||
describe('ACL SAVE', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
describe('ACL LOAD', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'SAVE']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ACL_LOAD.transformArguments(),
|
||||
['ACL', 'LOAD']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['ACL', 'LOAD'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,53 +1,53 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments, transformReply } from './ACL_LOG';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ACL_LOG from './ACL_LOG';
|
||||
|
||||
describe('ACL LOG', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'LOG']
|
||||
);
|
||||
});
|
||||
|
||||
it('with count', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(10),
|
||||
['ACL', 'LOG', '10']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ACL_LOG.transformArguments(),
|
||||
['ACL', 'LOG']
|
||||
);
|
||||
});
|
||||
|
||||
it('transformReply', () => {
|
||||
assert.deepEqual(
|
||||
transformReply([[
|
||||
'count',
|
||||
1,
|
||||
'reason',
|
||||
'auth',
|
||||
'context',
|
||||
'toplevel',
|
||||
'object',
|
||||
'AUTH',
|
||||
'username',
|
||||
'someuser',
|
||||
'age-seconds',
|
||||
'4.096',
|
||||
'client-info',
|
||||
'id=6 addr=127.0.0.1:63026 fd=8 name= age=9 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=48 qbuf-free=32720 obl=0 oll=0 omem=0 events=r cmd=auth user=default'
|
||||
]]),
|
||||
[{
|
||||
count: 1,
|
||||
reason: 'auth',
|
||||
context: 'toplevel',
|
||||
object: 'AUTH',
|
||||
username: 'someuser',
|
||||
ageSeconds: 4.096,
|
||||
clientInfo: 'id=6 addr=127.0.0.1:63026 fd=8 name= age=9 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=48 qbuf-free=32720 obl=0 oll=0 omem=0 events=r cmd=auth user=default'
|
||||
}]
|
||||
);
|
||||
it('with count', () => {
|
||||
assert.deepEqual(
|
||||
ACL_LOG.transformArguments(10),
|
||||
['ACL', 'LOG', '10']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclLog', async client => {
|
||||
// make sure to create at least one log
|
||||
await Promise.all([
|
||||
client.aclSetUser('test', 'on >test'),
|
||||
client.auth({
|
||||
username: 'test',
|
||||
password: 'test'
|
||||
}),
|
||||
client.auth({
|
||||
username: 'default',
|
||||
password: ''
|
||||
})
|
||||
]);
|
||||
|
||||
const logs = await client.aclLog();
|
||||
assert.ok(Array.isArray(logs));
|
||||
for (const log of logs) {
|
||||
|
||||
assert.equal(typeof log.count, 'number');
|
||||
assert.equal(typeof log.timestamp, 'number');
|
||||
assert.equal(typeof log.username, 'string');
|
||||
assert.equal(typeof log.clientId, 'string');
|
||||
assert.equal(typeof log.command, 'string');
|
||||
assert.equal(typeof log.args, 'string');
|
||||
assert.equal(typeof log.key, 'string');
|
||||
assert.equal(typeof log.result, 'number');
|
||||
assert.equal(typeof log.duration, 'number');
|
||||
}
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,50 +1,38 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { Resp2Reply } from '../RESP/types';
|
||||
import { ArrayReply, BlobStringReply, Command, NumberReply, TuplesToMapReply } from '../RESP/types';
|
||||
|
||||
export function transformArguments(count?: number): RedisCommandArguments {
|
||||
export type AclLogReply = ArrayReply<TuplesToMapReply<[
|
||||
[BlobStringReply<'count'>, NumberReply],
|
||||
[BlobStringReply<'reason'>, BlobStringReply],
|
||||
[BlobStringReply<'context'>, BlobStringReply],
|
||||
[BlobStringReply<'object'>, BlobStringReply],
|
||||
[BlobStringReply<'username'>, BlobStringReply],
|
||||
[BlobStringReply<'age-seconds'>, BlobStringReply],
|
||||
[BlobStringReply<'client-info'>, BlobStringReply]
|
||||
]>>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(count?: number) {
|
||||
const args = ['ACL', 'LOG'];
|
||||
|
||||
if (count) {
|
||||
args.push(count.toString());
|
||||
if (count !== undefined) {
|
||||
args.push(count.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
type AclLogRawReply = [
|
||||
_: RedisCommandArgument,
|
||||
count: number,
|
||||
_: RedisCommandArgument,
|
||||
reason: RedisCommandArgument,
|
||||
_: RedisCommandArgument,
|
||||
context: RedisCommandArgument,
|
||||
_: RedisCommandArgument,
|
||||
object: RedisCommandArgument,
|
||||
_: RedisCommandArgument,
|
||||
username: RedisCommandArgument,
|
||||
_: RedisCommandArgument,
|
||||
ageSeconds: RedisCommandArgument,
|
||||
_: RedisCommandArgument,
|
||||
clientInfo: RedisCommandArgument
|
||||
];
|
||||
|
||||
interface AclLog {
|
||||
count: number;
|
||||
reason: RedisCommandArgument;
|
||||
context: RedisCommandArgument;
|
||||
object: RedisCommandArgument;
|
||||
username: RedisCommandArgument;
|
||||
ageSeconds: number;
|
||||
clientInfo: RedisCommandArgument;
|
||||
}
|
||||
|
||||
export function transformReply(reply: Array<AclLogRawReply>): Array<AclLog> {
|
||||
return reply.map(log => ({
|
||||
count: log[1],
|
||||
reason: log[3],
|
||||
context: log[5],
|
||||
object: log[7],
|
||||
username: log[9],
|
||||
ageSeconds: Number(log[11]),
|
||||
clientInfo: log[13]
|
||||
}));
|
||||
}
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: Resp2Reply<AclLogReply>) => ({
|
||||
count: Number(reply[1]),
|
||||
reason: reply[3],
|
||||
context: reply[5],
|
||||
object: reply[7],
|
||||
username: reply[9],
|
||||
'age-seconds': Number(reply[11]),
|
||||
'client-info': reply[13]
|
||||
}),
|
||||
3: undefined as unknown as () => AclLogReply
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,14 +1,21 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './ACL_LOG_RESET';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import ACL_LOG_RESET from './ACL_LOG_RESET';
|
||||
|
||||
describe('ACL LOG RESET', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'LOG', 'RESET']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ACL_LOG_RESET.transformArguments(),
|
||||
['ACL', 'LOG', 'RESET']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.aclLogReset', async client => {
|
||||
assert.equal(
|
||||
await client.aclLogReset(),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,7 +1,11 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import ACL_LOG from './ACL_LOG';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: ACL_LOG.IS_READ_ONLY,
|
||||
transformArguments() {
|
||||
return ['ACL', 'LOG', 'RESET'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils from '../test-utils';
|
||||
import { transformArguments } from './ACL_LOAD';
|
||||
import ACL_SAVE from './ACL_SAVE';
|
||||
|
||||
describe('ACL LOAD', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
describe('ACL SAVE', () => {
|
||||
testUtils.isVersionGreaterThanHook([6]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['ACL', 'LOAD']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
ACL_SAVE.transformArguments(),
|
||||
['ACL', 'SAVE']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['ACL', 'SAVE'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export function transformArguments(
|
||||
username: RedisCommandArgument,
|
||||
rule: RedisCommandArgument | Array<RedisCommandArgument>
|
||||
): RedisCommandArguments {
|
||||
return pushVerdictArguments(['ACL', 'SETUSER', username], rule);
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(username: RedisArgument, rule: RedisVariadicArgument) {
|
||||
return pushVariadicArguments(['ACL', 'SETUSER', username], rule);
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['ACL', 'USERS'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
return ['ACL', 'WHOAMI'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['ACL', 'USERS'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,22 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './APPEND';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import APPEND from './APPEND';
|
||||
|
||||
describe('APPEND', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', 'value'),
|
||||
['APPEND', 'key', 'value']
|
||||
);
|
||||
});
|
||||
describe.only('APPEND', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
APPEND.transformArguments('key', 'value'),
|
||||
['APPEND', 'key', 'value']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testAll('append', async client => {
|
||||
assert.equal(
|
||||
await client.append('key', 'value'),
|
||||
5
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,12 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
value: RedisCommandArgument
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, value: RedisArgument) {
|
||||
return ['APPEND', key, value];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArguments, RedisCommandArgument } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['ASKING'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,25 +1,25 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './AUTH';
|
||||
import AUTH from './AUTH';
|
||||
|
||||
describe('AUTH', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('password only', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
password: 'password'
|
||||
}),
|
||||
['AUTH', 'password']
|
||||
);
|
||||
});
|
||||
|
||||
it('username & password', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
}),
|
||||
['AUTH', 'username', 'password']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('password only', () => {
|
||||
assert.deepEqual(
|
||||
AUTH.transformArguments({
|
||||
password: 'password'
|
||||
}),
|
||||
['AUTH', 'password']
|
||||
);
|
||||
});
|
||||
|
||||
it('username & password', () => {
|
||||
assert.deepEqual(
|
||||
AUTH.transformArguments({
|
||||
username: 'username',
|
||||
password: 'password'
|
||||
}),
|
||||
['AUTH', 'username', 'password']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,16 +1,23 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export interface AuthOptions {
|
||||
username?: RedisCommandArgument;
|
||||
password: RedisCommandArgument;
|
||||
username?: RedisArgument;
|
||||
password: RedisArgument;
|
||||
}
|
||||
|
||||
export function transformArguments({ username, password }: AuthOptions): RedisCommandArguments {
|
||||
if (!username) {
|
||||
return ['AUTH', password];
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments({ username, password }: AuthOptions) {
|
||||
const args: Array<RedisArgument> = ['AUTH'];
|
||||
|
||||
if (username !== undefined) {
|
||||
args.push(username);
|
||||
}
|
||||
|
||||
return ['AUTH', username, password];
|
||||
}
|
||||
args.push(password);
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['BGREWRITEAOF'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,17 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
interface BgSaveOptions {
|
||||
SCHEDULE?: true;
|
||||
}
|
||||
|
||||
export function transformArguments(options?: BgSaveOptions): RedisCommandArguments {
|
||||
const args = ['BGSAVE'];
|
||||
|
||||
if (options?.SCHEDULE) {
|
||||
args.push('SCHEDULE');
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['BGSAVE'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,33 +1,29 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
interface BitCountRange {
|
||||
start: number;
|
||||
end: number;
|
||||
mode?: 'BYTE' | 'BIT';
|
||||
export interface BitCountRange {
|
||||
start: number;
|
||||
end: number;
|
||||
mode?: 'BYTE' | 'BIT';
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
range?: BitCountRange
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, range?: BitCountRange) {
|
||||
const args = ['BITCOUNT', key];
|
||||
|
||||
if (range) {
|
||||
args.push(
|
||||
range.start.toString(),
|
||||
range.end.toString()
|
||||
);
|
||||
args.push(
|
||||
range.start.toString(),
|
||||
range.end.toString()
|
||||
);
|
||||
|
||||
if (range.mode) {
|
||||
args.push(range.mode);
|
||||
}
|
||||
if (range.mode) {
|
||||
args.push(range.mode);
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,46 +1,49 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './BITFIELD';
|
||||
import BITFIELD from './BITFIELD';
|
||||
|
||||
describe('BITFIELD', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', [{
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'WRAP'
|
||||
}, {
|
||||
operation: 'GET',
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}, {
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'SAT'
|
||||
}, {
|
||||
operation: 'SET',
|
||||
encoding: 'i16',
|
||||
offset: 1,
|
||||
value: 0
|
||||
}, {
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'FAIL'
|
||||
}, {
|
||||
operation: 'INCRBY',
|
||||
encoding: 'i32',
|
||||
offset: 2,
|
||||
increment: 1
|
||||
}]),
|
||||
['BITFIELD', 'key', 'OVERFLOW', 'WRAP', 'GET', 'i8', '0', 'OVERFLOW', 'SAT', 'SET', 'i16', '1', '0', 'OVERFLOW', 'FAIL', 'INCRBY', 'i32', '2', '1']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
BITFIELD.transformArguments('key', [{
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'WRAP'
|
||||
}, {
|
||||
operation: 'GET',
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}, {
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'SAT'
|
||||
}, {
|
||||
operation: 'SET',
|
||||
encoding: 'i16',
|
||||
offset: 1,
|
||||
value: 0
|
||||
}, {
|
||||
operation: 'OVERFLOW',
|
||||
behavior: 'FAIL'
|
||||
}, {
|
||||
operation: 'INCRBY',
|
||||
encoding: 'i32',
|
||||
offset: 2,
|
||||
increment: 1
|
||||
}]),
|
||||
['BITFIELD', 'key', 'OVERFLOW', 'WRAP', 'GET', 'i8', '0', 'OVERFLOW', 'SAT', 'SET', 'i16', '1', '0', 'OVERFLOW', 'FAIL', 'INCRBY', 'i32', '2', '1']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.bitField', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bitField('key', [{
|
||||
operation: 'GET',
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
[0]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
testUtils.testAll('bitField', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bitField('key', [{
|
||||
operation: 'GET',
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
[0]
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,80 +1,87 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
import { RedisArgument, ArrayReply, NumberReply, NullReply, Command } from '../RESP/types';
|
||||
|
||||
export type BitFieldEncoding = `${'i' | 'u'}${number}`;
|
||||
|
||||
export interface BitFieldOperation<S extends string> {
|
||||
operation: S;
|
||||
operation: S;
|
||||
}
|
||||
|
||||
export interface BitFieldGetOperation extends BitFieldOperation<'GET'> {
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
}
|
||||
|
||||
interface BitFieldSetOperation extends BitFieldOperation<'SET'> {
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
value: number;
|
||||
export interface BitFieldSetOperation extends BitFieldOperation<'SET'> {
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface BitFieldIncrByOperation extends BitFieldOperation<'INCRBY'> {
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
increment: number;
|
||||
export interface BitFieldIncrByOperation extends BitFieldOperation<'INCRBY'> {
|
||||
encoding: BitFieldEncoding;
|
||||
offset: number | string;
|
||||
increment: number;
|
||||
}
|
||||
|
||||
interface BitFieldOverflowOperation extends BitFieldOperation<'OVERFLOW'> {
|
||||
behavior: string;
|
||||
export interface BitFieldOverflowOperation extends BitFieldOperation<'OVERFLOW'> {
|
||||
behavior: string;
|
||||
}
|
||||
|
||||
type BitFieldOperations = Array<
|
||||
BitFieldGetOperation |
|
||||
BitFieldSetOperation |
|
||||
BitFieldIncrByOperation |
|
||||
BitFieldOverflowOperation
|
||||
export type BitFieldOperations = Array<
|
||||
BitFieldGetOperation |
|
||||
BitFieldSetOperation |
|
||||
BitFieldIncrByOperation |
|
||||
BitFieldOverflowOperation
|
||||
>;
|
||||
|
||||
export function transformArguments(key: string, operations: BitFieldOperations): Array<string> {
|
||||
export type BitFieldRoOperations = Array<
|
||||
Omit<BitFieldGetOperation, 'operation'>
|
||||
>;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, operations: BitFieldOperations) {
|
||||
const args = ['BITFIELD', key];
|
||||
|
||||
for (const options of operations) {
|
||||
switch (options.operation) {
|
||||
case 'GET':
|
||||
args.push(
|
||||
'GET',
|
||||
options.encoding,
|
||||
options.offset.toString()
|
||||
);
|
||||
break;
|
||||
switch (options.operation) {
|
||||
case 'GET':
|
||||
args.push(
|
||||
'GET',
|
||||
options.encoding,
|
||||
options.offset.toString()
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SET':
|
||||
args.push(
|
||||
'SET',
|
||||
options.encoding,
|
||||
options.offset.toString(),
|
||||
options.value.toString()
|
||||
);
|
||||
break;
|
||||
case 'SET':
|
||||
args.push(
|
||||
'SET',
|
||||
options.encoding,
|
||||
options.offset.toString(),
|
||||
options.value.toString()
|
||||
);
|
||||
break;
|
||||
|
||||
case 'INCRBY':
|
||||
args.push(
|
||||
'INCRBY',
|
||||
options.encoding,
|
||||
options.offset.toString(),
|
||||
options.increment.toString()
|
||||
);
|
||||
break;
|
||||
case 'INCRBY':
|
||||
args.push(
|
||||
'INCRBY',
|
||||
options.encoding,
|
||||
options.offset.toString(),
|
||||
options.increment.toString()
|
||||
);
|
||||
break;
|
||||
|
||||
case 'OVERFLOW':
|
||||
args.push(
|
||||
'OVERFLOW',
|
||||
options.behavior
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'OVERFLOW':
|
||||
args.push(
|
||||
'OVERFLOW',
|
||||
options.behavior
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<number | null>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<NumberReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,27 +1,30 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './BITFIELD_RO';
|
||||
import BITFIELD_RO from './BITFIELD_RO';
|
||||
|
||||
describe('BITFIELD RO', () => {
|
||||
testUtils.isVersionGreaterThanHook([6, 2]);
|
||||
describe('BITFIELD_RO', () => {
|
||||
testUtils.isVersionGreaterThanHook([6, 2]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', [{
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
['BITFIELD_RO', 'key', 'GET', 'i8', '0']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
BITFIELD_RO.transformArguments('key', [{
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
['BITFIELD_RO', 'key', 'GET', 'i8', '0']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.bitFieldRo', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bitFieldRo('key', [{
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
[0]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
testUtils.testAll('bitFieldRo', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bitFieldRo('key', [{
|
||||
encoding: 'i8',
|
||||
offset: 0
|
||||
}]),
|
||||
[0]
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,26 +1,25 @@
|
||||
import { RedisArgument, ArrayReply, NumberReply, Command } from '../RESP/types';
|
||||
import { BitFieldGetOperation } from './BITFIELD';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
type BitFieldRoOperations = Array<
|
||||
Omit<BitFieldGetOperation, 'operation'> &
|
||||
Partial<Pick<BitFieldGetOperation, 'operation'>>
|
||||
export type BitFieldRoOperations = Array<
|
||||
Omit<BitFieldGetOperation, 'operation'>
|
||||
>;
|
||||
|
||||
export function transformArguments(key: string, operations: BitFieldRoOperations): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, operations: BitFieldRoOperations) {
|
||||
const args = ['BITFIELD_RO', key];
|
||||
|
||||
for (const operation of operations) {
|
||||
args.push(
|
||||
'GET',
|
||||
operation.encoding,
|
||||
operation.offset.toString()
|
||||
);
|
||||
args.push(
|
||||
'GET',
|
||||
operation.encoding,
|
||||
operation.offset.toString()
|
||||
);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<number | null>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<NumberReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,35 +1,31 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './BITOP';
|
||||
import BITOP from './BITOP';
|
||||
|
||||
describe('BITOP', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single key', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('AND', 'destKey', 'key'),
|
||||
['BITOP', 'AND', 'destKey', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple keys', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('AND', 'destKey', ['1', '2']),
|
||||
['BITOP', 'AND', 'destKey', '1', '2']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('single key', () => {
|
||||
assert.deepEqual(
|
||||
BITOP.transformArguments('AND', 'destKey', 'key'),
|
||||
['BITOP', 'AND', 'destKey', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.bitOp', async client => {
|
||||
assert.equal(
|
||||
await client.bitOp('AND', 'destKey', 'key'),
|
||||
0
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
it('multiple keys', () => {
|
||||
assert.deepEqual(
|
||||
BITOP.transformArguments('AND', 'destKey', ['1', '2']),
|
||||
['BITOP', 'AND', 'destKey', '1', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithCluster('cluster.bitOp', async cluster => {
|
||||
assert.equal(
|
||||
await cluster.bitOp('AND', '{tag}destKey', '{tag}key'),
|
||||
0
|
||||
);
|
||||
}, GLOBAL.CLUSTERS.OPEN);
|
||||
testUtils.testAll('client.bitOp', async client => {
|
||||
assert.equal(
|
||||
await client.bitOp('AND', '{tag}destKey', '{tag}key'),
|
||||
0
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,16 +1,17 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { NumberReply, Command, RedisArgument } from '../RESP/types';
|
||||
import { RedisVariadicArgument, pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 2;
|
||||
export type BitOperations = 'AND' | 'OR' | 'XOR' | 'NOT';
|
||||
|
||||
type BitOperations = 'AND' | 'OR' | 'XOR' | 'NOT';
|
||||
|
||||
export function transformArguments(
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 2,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
operation: BitOperations,
|
||||
destKey: RedisCommandArgument,
|
||||
key: RedisCommandArgument | Array<RedisCommandArgument>
|
||||
): RedisCommandArguments {
|
||||
return pushVerdictArguments(['BITOP', operation, destKey], key);
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
destKey: RedisArgument,
|
||||
key: RedisVariadicArgument
|
||||
) {
|
||||
return pushVariadicArguments(['BITOP', operation, destKey], key);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,32 +1,31 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
import { BitValue } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
bit: BitValue,
|
||||
start?: number,
|
||||
end?: number,
|
||||
mode?: 'BYTE' | 'BIT'
|
||||
): RedisCommandArguments {
|
||||
) {
|
||||
const args = ['BITPOS', key, bit.toString()];
|
||||
|
||||
if (typeof start === 'number') {
|
||||
args.push(start.toString());
|
||||
args.push(start.toString());
|
||||
}
|
||||
|
||||
if (typeof end === 'number') {
|
||||
args.push(end.toString());
|
||||
args.push(end.toString());
|
||||
}
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,23 +1,24 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
import { ListSide } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
source: RedisCommandArgument,
|
||||
destination: RedisCommandArgument,
|
||||
sourceDirection: ListSide,
|
||||
destinationDirection: ListSide,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
source: RedisArgument,
|
||||
destination: RedisArgument,
|
||||
sourceSide: ListSide,
|
||||
destinationSide: ListSide,
|
||||
timeout: number
|
||||
): RedisCommandArguments {
|
||||
) {
|
||||
return [
|
||||
'BLMOVE',
|
||||
source,
|
||||
destination,
|
||||
sourceDirection,
|
||||
destinationDirection,
|
||||
timeout.toString()
|
||||
'BLMOVE',
|
||||
source,
|
||||
destination,
|
||||
sourceSide,
|
||||
destinationSide,
|
||||
timeout.toString()
|
||||
];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument | null;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,20 +1,22 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, Command } from '../RESP/types';
|
||||
import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers';
|
||||
import LMPOP from './LMPOP';
|
||||
|
||||
export const FIRST_KEY_INDEX = 3;
|
||||
|
||||
export function transformArguments(
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 3,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
timeout: number,
|
||||
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||
keys: RedisArgument | Array<RedisArgument>,
|
||||
side: ListSide,
|
||||
options?: LMPopOptions
|
||||
): RedisCommandArguments {
|
||||
) {
|
||||
return transformLMPopArguments(
|
||||
['BLMPOP', timeout.toString()],
|
||||
keys,
|
||||
side,
|
||||
options
|
||||
['BLMPOP', timeout.toString()],
|
||||
keys,
|
||||
side,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
export { transformReply } from './LMPOP';
|
||||
},
|
||||
transformReply: LMPOP.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,31 +1,23 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
import { pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
key: RedisArgument | Array<RedisArgument>,
|
||||
timeout: number
|
||||
): RedisCommandArguments {
|
||||
const args = pushVerdictArguments(['BLPOP'], keys);
|
||||
|
||||
) {
|
||||
const args = pushVariadicArguments(['BRPOP'], key);
|
||||
args.push(timeout.toString());
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
type BLPopRawReply = null | [RedisCommandArgument, RedisCommandArgument];
|
||||
|
||||
type BLPopReply = null | {
|
||||
key: RedisCommandArgument;
|
||||
element: RedisCommandArgument;
|
||||
};
|
||||
|
||||
export function transformReply(reply: BLPopRawReply): BLPopReply {
|
||||
},
|
||||
transformReply(reply: NullReply | [BlobStringReply, BlobStringReply]) {
|
||||
if (reply === null) return null;
|
||||
|
||||
return {
|
||||
key: reply[0],
|
||||
element: reply[1]
|
||||
key: reply[0],
|
||||
element: reply[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
import { pushVariadicArguments } from './generic-transformers';
|
||||
import BLPOP from './BLPOP';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
key: RedisArgument | Array<RedisArgument>,
|
||||
timeout: number
|
||||
): RedisCommandArguments {
|
||||
const args = pushVerdictArguments(['BRPOP'], key);
|
||||
|
||||
) {
|
||||
const args = pushVariadicArguments(['BRPOP'], key);
|
||||
args.push(timeout.toString());
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformReply } from './BLPOP';
|
||||
},
|
||||
transformReply: BLPOP.transformReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,14 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
source: RedisCommandArgument,
|
||||
destination: RedisCommandArgument,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
source: RedisArgument,
|
||||
destination: RedisArgument,
|
||||
timeout: number
|
||||
): RedisCommandArguments {
|
||||
) {
|
||||
return ['BRPOPLPUSH', source, destination, timeout.toString()];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument | null;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -18,3 +18,17 @@ export function transformArguments(
|
||||
}
|
||||
|
||||
export { transformReply } from './ZMPOP';
|
||||
|
||||
|
||||
import { Command } from '../RESP/types';
|
||||
import ZMPOP from './ZMPOP';
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: false,
|
||||
FIRST_KEY_INDEX: 3,
|
||||
transformArguments() {
|
||||
return ['BZMPOP'];
|
||||
},
|
||||
transformReply: ZMPOP.transformReply
|
||||
} as const satisfies Command;
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments, transformNumberInfinityReply, ZMember } from './generic-transformers';
|
||||
import { pushVariadicArguments, transformNumberInfinityReply, ZMember } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
@@ -7,7 +7,7 @@ export function transformArguments(
|
||||
key: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||
timeout: number
|
||||
): RedisCommandArguments {
|
||||
const args = pushVerdictArguments(['BZPOPMAX'], key);
|
||||
const args = pushVariadicArguments(['BZPOPMAX'], key);
|
||||
|
||||
args.push(timeout.toString());
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
@@ -7,7 +7,7 @@ export function transformArguments(
|
||||
key: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||
timeout: number
|
||||
): RedisCommandArguments {
|
||||
const args = pushVerdictArguments(['BZPOPMIN'], key);
|
||||
const args = pushVariadicArguments(['BZPOPMIN'], key);
|
||||
|
||||
args.push(timeout.toString());
|
||||
|
||||
|
@@ -1,20 +1,20 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './CLIENT_CACHING';
|
||||
import CLIENT_CACHING from './CLIENT_CACHING';
|
||||
|
||||
describe('CLIENT CACHING', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('true', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(true),
|
||||
['CLIENT', 'CACHING', 'YES']
|
||||
);
|
||||
});
|
||||
|
||||
it('false', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(false),
|
||||
['CLIENT', 'CACHING', 'NO']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('true', () => {
|
||||
assert.deepEqual(
|
||||
CLIENT_CACHING.transformArguments(true),
|
||||
['CLIENT', 'CACHING', 'YES']
|
||||
);
|
||||
});
|
||||
|
||||
it('false', () => {
|
||||
assert.deepEqual(
|
||||
CLIENT_CACHING.transformArguments(false),
|
||||
['CLIENT', 'CACHING', 'NO']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(value: boolean): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(value: boolean) {
|
||||
return [
|
||||
'CLIENT',
|
||||
'CACHING',
|
||||
value ? 'YES' : 'NO'
|
||||
'CLIENT',
|
||||
'CACHING',
|
||||
value ? 'YES' : 'NO'
|
||||
];
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK' | Buffer;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './CLIENT_GETNAME';
|
||||
import CLIENT_GETNAME from './CLIENT_GETNAME';
|
||||
|
||||
describe('CLIENT GETNAME', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['CLIENT', 'GETNAME']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
CLIENT_GETNAME.transformArguments(),
|
||||
['CLIENT', 'GETNAME']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,12 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
return ['CLIENT', 'GETNAME'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): string | null;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return [
|
||||
'CLIENT',
|
||||
'GETNAME'
|
||||
];
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './CLIENT_GETREDIR';
|
||||
import CLIENT_GETREDIR from './CLIENT_GETREDIR';
|
||||
|
||||
describe('CLIENT GETREDIR', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['CLIENT', 'GETREDIR']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
CLIENT_GETREDIR.transformArguments(),
|
||||
['CLIENT', 'GETREDIR']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
return ['CLIENT', 'GETREDIR'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLIENT', 'GETREDIR']
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,19 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './CLIENT_ID';
|
||||
import CLIENT_ID from './CLIENT_ID';
|
||||
|
||||
describe('CLIENT ID', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['CLIENT', 'ID']
|
||||
);
|
||||
});
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
CLIENT_ID.transformArguments(),
|
||||
['CLIENT', 'ID']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.clientId', async client => {
|
||||
assert.equal(
|
||||
typeof (await client.clientId()),
|
||||
'number'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
testUtils.testWithClient('client.clientId', async client => {
|
||||
assert.equal(
|
||||
typeof (await client.clientId()),
|
||||
'number'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,7 +1,9 @@
|
||||
export const IS_READ_ONLY = true;
|
||||
import { NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLIENT', 'ID'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,89 +1,115 @@
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CLIENT', 'INFO'];
|
||||
}
|
||||
import { Command, VerbatimStringReply } from '../RESP/types';
|
||||
|
||||
export interface ClientInfoReply {
|
||||
id: number;
|
||||
addr: string;
|
||||
laddr?: string; // 6.2
|
||||
fd: number;
|
||||
name: string;
|
||||
age: number;
|
||||
idle: number;
|
||||
flags: string;
|
||||
db: number;
|
||||
sub: number;
|
||||
psub: number;
|
||||
ssub?: number; // 7.0.3
|
||||
multi: number;
|
||||
qbuf: number;
|
||||
qbufFree: number;
|
||||
argvMem?: number; // 6.0
|
||||
multiMem?: number; // 7.0
|
||||
obl: number;
|
||||
oll: number;
|
||||
omem: number;
|
||||
totMem?: number; // 6.0
|
||||
events: string;
|
||||
cmd: string;
|
||||
user?: string; // 6.0
|
||||
redir?: number; // 6.2
|
||||
resp?: number; // 7.0
|
||||
id: number;
|
||||
addr: string;
|
||||
/**
|
||||
* available since 6.2
|
||||
*/
|
||||
laddr?: string;
|
||||
fd: number;
|
||||
name: string;
|
||||
age: number;
|
||||
idle: number;
|
||||
flags: string;
|
||||
db: number;
|
||||
sub: number;
|
||||
psub: number;
|
||||
/**
|
||||
* available since 7.0.3
|
||||
*/
|
||||
ssub?: number;
|
||||
multi: number;
|
||||
qbuf: number;
|
||||
qbufFree: number;
|
||||
/**
|
||||
* available since 6.0
|
||||
*/
|
||||
argvMem?: number;
|
||||
/**
|
||||
* available since 7.0
|
||||
*/
|
||||
multiMem?: number;
|
||||
obl: number;
|
||||
oll: number;
|
||||
omem: number;
|
||||
/**
|
||||
* available since 6.0
|
||||
*/
|
||||
totMem?: number;
|
||||
events: string;
|
||||
cmd: string;
|
||||
/**
|
||||
* available since 6.0
|
||||
*/
|
||||
user?: string;
|
||||
/**
|
||||
* available since 6.2
|
||||
*/
|
||||
redir?: number;
|
||||
/**
|
||||
* available since 7.0
|
||||
*/
|
||||
resp?: number;
|
||||
}
|
||||
|
||||
const CLIENT_INFO_REGEX = /([^\s=]+)=([^\s]*)/g;
|
||||
|
||||
export function transformReply(rawReply: string): ClientInfoReply {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLIENT', 'INFO']
|
||||
},
|
||||
transformReply(rawReply: VerbatimStringReply) {
|
||||
const map: Record<string, string> = {};
|
||||
for (const item of rawReply.matchAll(CLIENT_INFO_REGEX)) {
|
||||
map[item[1]] = item[2];
|
||||
for (const item of rawReply.toString().matchAll(CLIENT_INFO_REGEX)) {
|
||||
map[item[1]] = item[2];
|
||||
}
|
||||
|
||||
const reply: ClientInfoReply = {
|
||||
id: Number(map.id),
|
||||
addr: map.addr,
|
||||
fd: Number(map.fd),
|
||||
name: map.name,
|
||||
age: Number(map.age),
|
||||
idle: Number(map.idle),
|
||||
flags: map.flags,
|
||||
db: Number(map.db),
|
||||
sub: Number(map.sub),
|
||||
psub: Number(map.psub),
|
||||
multi: Number(map.multi),
|
||||
qbuf: Number(map.qbuf),
|
||||
qbufFree: Number(map['qbuf-free']),
|
||||
argvMem: Number(map['argv-mem']),
|
||||
obl: Number(map.obl),
|
||||
oll: Number(map.oll),
|
||||
omem: Number(map.omem),
|
||||
totMem: Number(map['tot-mem']),
|
||||
events: map.events,
|
||||
cmd: map.cmd,
|
||||
user: map.user
|
||||
id: Number(map.id),
|
||||
addr: map.addr,
|
||||
fd: Number(map.fd),
|
||||
name: map.name,
|
||||
age: Number(map.age),
|
||||
idle: Number(map.idle),
|
||||
flags: map.flags,
|
||||
db: Number(map.db),
|
||||
sub: Number(map.sub),
|
||||
psub: Number(map.psub),
|
||||
multi: Number(map.multi),
|
||||
qbuf: Number(map.qbuf),
|
||||
qbufFree: Number(map['qbuf-free']),
|
||||
argvMem: Number(map['argv-mem']),
|
||||
obl: Number(map.obl),
|
||||
oll: Number(map.oll),
|
||||
omem: Number(map.omem),
|
||||
totMem: Number(map['tot-mem']),
|
||||
events: map.events,
|
||||
cmd: map.cmd,
|
||||
user: map.user
|
||||
};
|
||||
|
||||
if (map.laddr !== undefined) {
|
||||
reply.laddr = map.laddr;
|
||||
reply.laddr = map.laddr;
|
||||
}
|
||||
|
||||
if (map.redir !== undefined) {
|
||||
reply.redir = Number(map.redir);
|
||||
reply.redir = Number(map.redir);
|
||||
}
|
||||
|
||||
if (map.ssub !== undefined) {
|
||||
reply.ssub = Number(map.ssub);
|
||||
reply.ssub = Number(map.ssub);
|
||||
}
|
||||
|
||||
if (map['multi-mem'] !== undefined) {
|
||||
reply.multiMem = Number(map['multi-mem']);
|
||||
reply.multiMem = Number(map['multi-mem']);
|
||||
}
|
||||
|
||||
if (map.resp !== undefined) {
|
||||
reply.resp = Number(map.resp);
|
||||
reply.resp = Number(map.resp);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
@@ -2,109 +2,109 @@ import { strict as assert } from 'assert';
|
||||
import { ClientKillFilters, transformArguments } from './CLIENT_KILL';
|
||||
|
||||
describe('CLIENT KILL', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('ADDRESS', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.ADDRESS,
|
||||
address: 'ip:6379'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'ADDR', 'ip:6379']
|
||||
);
|
||||
});
|
||||
|
||||
it('LOCAL_ADDRESS', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.LOCAL_ADDRESS,
|
||||
localAddress: 'ip:6379'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'LADDR', 'ip:6379']
|
||||
);
|
||||
});
|
||||
|
||||
describe('ID', () => {
|
||||
it('string', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.ID,
|
||||
id: '1'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'ID', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('number', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.ID,
|
||||
id: 1
|
||||
}),
|
||||
['CLIENT', 'KILL', 'ID', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('TYPE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.TYPE,
|
||||
type: 'master'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'TYPE', 'master']
|
||||
);
|
||||
});
|
||||
|
||||
it('USER', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.USER,
|
||||
username: 'username'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'USER', 'username']
|
||||
);
|
||||
});
|
||||
|
||||
describe('SKIP_ME', () => {
|
||||
it('undefined', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(ClientKillFilters.SKIP_ME),
|
||||
['CLIENT', 'KILL', 'SKIPME']
|
||||
);
|
||||
});
|
||||
|
||||
it('true', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.SKIP_ME,
|
||||
skipMe: true
|
||||
}),
|
||||
['CLIENT', 'KILL', 'SKIPME', 'yes']
|
||||
);
|
||||
});
|
||||
|
||||
it('false', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.SKIP_ME,
|
||||
skipMe: false
|
||||
}),
|
||||
['CLIENT', 'KILL', 'SKIPME', 'no']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('TYPE & SKIP_ME', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments([
|
||||
{
|
||||
filter: ClientKillFilters.TYPE,
|
||||
type: 'master'
|
||||
},
|
||||
ClientKillFilters.SKIP_ME
|
||||
]),
|
||||
['CLIENT', 'KILL', 'TYPE', 'master', 'SKIPME']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('ADDRESS', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.ADDRESS,
|
||||
address: 'ip:6379'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'ADDR', 'ip:6379']
|
||||
);
|
||||
});
|
||||
|
||||
it('LOCAL_ADDRESS', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.LOCAL_ADDRESS,
|
||||
localAddress: 'ip:6379'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'LADDR', 'ip:6379']
|
||||
);
|
||||
});
|
||||
|
||||
describe('ID', () => {
|
||||
it('string', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.ID,
|
||||
id: '1'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'ID', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('number', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.ID,
|
||||
id: 1
|
||||
}),
|
||||
['CLIENT', 'KILL', 'ID', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('TYPE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.TYPE,
|
||||
type: 'master'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'TYPE', 'master']
|
||||
);
|
||||
});
|
||||
|
||||
it('USER', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.USER,
|
||||
username: 'username'
|
||||
}),
|
||||
['CLIENT', 'KILL', 'USER', 'username']
|
||||
);
|
||||
});
|
||||
|
||||
describe('SKIP_ME', () => {
|
||||
it('undefined', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(ClientKillFilters.SKIP_ME),
|
||||
['CLIENT', 'KILL', 'SKIPME']
|
||||
);
|
||||
});
|
||||
|
||||
it('true', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.SKIP_ME,
|
||||
skipMe: true
|
||||
}),
|
||||
['CLIENT', 'KILL', 'SKIPME', 'yes']
|
||||
);
|
||||
});
|
||||
|
||||
it('false', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments({
|
||||
filter: ClientKillFilters.SKIP_ME,
|
||||
skipMe: false
|
||||
}),
|
||||
['CLIENT', 'KILL', 'SKIPME', 'no']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('TYPE & SKIP_ME', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments([
|
||||
{
|
||||
filter: ClientKillFilters.TYPE,
|
||||
type: 'master'
|
||||
},
|
||||
ClientKillFilters.SKIP_ME
|
||||
]),
|
||||
['CLIENT', 'KILL', 'TYPE', 'master', 'SKIPME']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,95 +1,99 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export enum ClientKillFilters {
|
||||
ADDRESS = 'ADDR',
|
||||
LOCAL_ADDRESS = 'LADDR',
|
||||
ID = 'ID',
|
||||
TYPE = 'TYPE',
|
||||
USER = 'USER',
|
||||
SKIP_ME = 'SKIPME'
|
||||
export const CLIENT_KILL_FILTERS = {
|
||||
ADDRESS: 'ADDR',
|
||||
LOCAL_ADDRESS: 'LADDR',
|
||||
ID: 'ID',
|
||||
TYPE: 'TYPE',
|
||||
USER: 'USER',
|
||||
SKIP_ME: 'SKIPME'
|
||||
} as const;
|
||||
|
||||
type CLIENT_KILL_FILTERS = typeof CLIENT_KILL_FILTERS;
|
||||
|
||||
export interface ClientKillFilterCommon<T extends CLIENT_KILL_FILTERS[keyof CLIENT_KILL_FILTERS]> {
|
||||
filter: T;
|
||||
}
|
||||
|
||||
interface KillFilter<T extends ClientKillFilters> {
|
||||
filter: T;
|
||||
export interface ClientKillAddress extends ClientKillFilterCommon<CLIENT_KILL_FILTERS['ADDRESS']> {
|
||||
address: `${string}:${number}`;
|
||||
}
|
||||
|
||||
interface KillAddress extends KillFilter<ClientKillFilters.ADDRESS> {
|
||||
address: `${string}:${number}`;
|
||||
export interface ClientKillLocalAddress extends ClientKillFilterCommon<CLIENT_KILL_FILTERS['LOCAL_ADDRESS']> {
|
||||
localAddress: `${string}:${number}`;
|
||||
}
|
||||
|
||||
interface KillLocalAddress extends KillFilter<ClientKillFilters.LOCAL_ADDRESS> {
|
||||
localAddress: `${string}:${number}`;
|
||||
export interface ClientKillId extends ClientKillFilterCommon<CLIENT_KILL_FILTERS['ID']> {
|
||||
id: number | `${number}`;
|
||||
}
|
||||
|
||||
interface KillId extends KillFilter<ClientKillFilters.ID> {
|
||||
id: number | `${number}`;
|
||||
export interface ClientKillType extends ClientKillFilterCommon<CLIENT_KILL_FILTERS['TYPE']> {
|
||||
type: 'normal' | 'master' | 'replica' | 'pubsub';
|
||||
}
|
||||
|
||||
interface KillType extends KillFilter<ClientKillFilters.TYPE> {
|
||||
type: 'normal' | 'master' | 'replica' | 'pubsub';
|
||||
export interface ClientKillUser extends ClientKillFilterCommon<CLIENT_KILL_FILTERS['USER']> {
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface KillUser extends KillFilter<ClientKillFilters.USER> {
|
||||
username: string;
|
||||
}
|
||||
|
||||
type KillSkipMe = ClientKillFilters.SKIP_ME | (KillFilter<ClientKillFilters.SKIP_ME> & {
|
||||
skipMe: boolean;
|
||||
export type ClientKillSkipMe = CLIENT_KILL_FILTERS['SKIP_ME'] | (ClientKillFilterCommon<CLIENT_KILL_FILTERS['SKIP_ME']> & {
|
||||
skipMe: boolean;
|
||||
});
|
||||
|
||||
type KillFilters = KillAddress | KillLocalAddress | KillId | KillType | KillUser | KillSkipMe;
|
||||
export type ClientKillFilter = ClientKillAddress | ClientKillLocalAddress | ClientKillId | ClientKillType | ClientKillUser | ClientKillSkipMe;
|
||||
|
||||
export function transformArguments(filters: KillFilters | Array<KillFilters>): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(filters: ClientKillFilter | Array<ClientKillFilter>) {
|
||||
const args = ['CLIENT', 'KILL'];
|
||||
|
||||
if (Array.isArray(filters)) {
|
||||
for (const filter of filters) {
|
||||
pushFilter(args, filter);
|
||||
}
|
||||
for (const filter of filters) {
|
||||
pushFilter(args, filter);
|
||||
}
|
||||
} else {
|
||||
pushFilter(args, filters);
|
||||
pushFilter(args, filters);
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
||||
function pushFilter(args: Array<RedisArgument>, filter: ClientKillFilter): void {
|
||||
if (filter === CLIENT_KILL_FILTERS.SKIP_ME) {
|
||||
args.push('SKIPME');
|
||||
return;
|
||||
}
|
||||
|
||||
args.push(filter.filter);
|
||||
|
||||
switch (filter.filter) {
|
||||
case CLIENT_KILL_FILTERS.ADDRESS:
|
||||
args.push(filter.address);
|
||||
break;
|
||||
|
||||
case CLIENT_KILL_FILTERS.LOCAL_ADDRESS:
|
||||
args.push(filter.localAddress);
|
||||
break;
|
||||
|
||||
case CLIENT_KILL_FILTERS.ID:
|
||||
args.push(
|
||||
typeof filter.id === 'number' ?
|
||||
filter.id.toString() :
|
||||
filter.id
|
||||
);
|
||||
break;
|
||||
|
||||
case CLIENT_KILL_FILTERS.TYPE:
|
||||
args.push(filter.type);
|
||||
break;
|
||||
|
||||
case CLIENT_KILL_FILTERS.USER:
|
||||
args.push(filter.username);
|
||||
break;
|
||||
|
||||
case CLIENT_KILL_FILTERS.SKIP_ME:
|
||||
args.push(filter.skipMe ? 'yes' : 'no');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function pushFilter(args: RedisCommandArguments, filter: KillFilters): void {
|
||||
if (filter === ClientKillFilters.SKIP_ME) {
|
||||
args.push('SKIPME');
|
||||
return;
|
||||
}
|
||||
|
||||
args.push(filter.filter);
|
||||
|
||||
switch(filter.filter) {
|
||||
case ClientKillFilters.ADDRESS:
|
||||
args.push(filter.address);
|
||||
break;
|
||||
|
||||
case ClientKillFilters.LOCAL_ADDRESS:
|
||||
args.push(filter.localAddress);
|
||||
break;
|
||||
|
||||
case ClientKillFilters.ID:
|
||||
args.push(
|
||||
typeof filter.id === 'number' ?
|
||||
filter.id.toString() :
|
||||
filter.id
|
||||
);
|
||||
break;
|
||||
|
||||
case ClientKillFilters.TYPE:
|
||||
args.push(filter.type);
|
||||
break;
|
||||
|
||||
case ClientKillFilters.USER:
|
||||
args.push(filter.username);
|
||||
break;
|
||||
|
||||
case ClientKillFilters.SKIP_ME:
|
||||
args.push(filter.skipMe ? 'yes' : 'no');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
|
@@ -1,43 +1,43 @@
|
||||
import { RedisCommandArguments, RedisCommandArgument } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { transformReply as transformClientInfoReply, ClientInfoReply } from './CLIENT_INFO';
|
||||
import { RedisArgument, VerbatimStringReply, Command } from '../RESP/types';
|
||||
import { pushVariadicArguments } from './generic-transformers';
|
||||
import CLIENT_INFO, { ClientInfoReply } from './CLIENT_INFO';
|
||||
|
||||
interface ListFilterType {
|
||||
TYPE: 'NORMAL' | 'MASTER' | 'REPLICA' | 'PUBSUB';
|
||||
ID?: never;
|
||||
export interface ListFilterType {
|
||||
TYPE: 'NORMAL' | 'MASTER' | 'REPLICA' | 'PUBSUB';
|
||||
ID?: never;
|
||||
}
|
||||
|
||||
interface ListFilterId {
|
||||
ID: Array<RedisCommandArgument>;
|
||||
TYPE?: never;
|
||||
export interface ListFilterId {
|
||||
ID: Array<RedisArgument>;
|
||||
TYPE?: never;
|
||||
}
|
||||
|
||||
export type ListFilter = ListFilterType | ListFilterId;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(filter?: ListFilter): RedisCommandArguments {
|
||||
let args: RedisCommandArguments = ['CLIENT', 'LIST'];
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(filter?: ListFilter) {
|
||||
let args: Array<RedisArgument> = ['CLIENT', 'LIST'];
|
||||
|
||||
if (filter) {
|
||||
if (filter.TYPE !== undefined) {
|
||||
args.push('TYPE', filter.TYPE);
|
||||
} else {
|
||||
args.push('ID');
|
||||
args = pushVerdictArguments(args, filter.ID);
|
||||
}
|
||||
if (filter.TYPE !== undefined) {
|
||||
args.push('TYPE', filter.TYPE);
|
||||
} else {
|
||||
args.push('ID');
|
||||
args = pushVariadicArguments(args, filter.ID);
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export function transformReply(rawReply: string): Array<ClientInfoReply> {
|
||||
const split = rawReply.split('\n'),
|
||||
length = split.length - 1,
|
||||
reply: Array<ClientInfoReply> = [];
|
||||
},
|
||||
transformReply(rawReply: VerbatimStringReply): Array<ClientInfoReply> {
|
||||
const split = rawReply.toString().split('\n'),
|
||||
length = split.length - 1,
|
||||
reply: Array<ClientInfoReply> = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
reply.push(transformClientInfoReply(split[i]));
|
||||
reply.push(CLIENT_INFO.transformReply(split[i] as VerbatimStringReply));
|
||||
}
|
||||
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(value: boolean): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(value: boolean) {
|
||||
return [
|
||||
'CLIENT',
|
||||
'NO-EVICT',
|
||||
value ? 'ON' : 'OFF'
|
||||
'CLIENT',
|
||||
'NO-EVICT',
|
||||
value ? 'ON' : 'OFF'
|
||||
];
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK' | Buffer;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,20 +1,19 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(
|
||||
timeout: number,
|
||||
mode?: 'WRITE' | 'ALL'
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(timeout: number, mode?: 'WRITE' | 'ALL') {
|
||||
const args = [
|
||||
'CLIENT',
|
||||
'PAUSE',
|
||||
timeout.toString()
|
||||
'CLIENT',
|
||||
'PAUSE',
|
||||
timeout.toString()
|
||||
];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK' | Buffer;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(name: RedisCommandArgument): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(name: RedisArgument) {
|
||||
return ['CLIENT', 'SETNAME', name];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLIENT', 'UNPAUSE'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK' | Buffer;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { pushVerdictNumberArguments } from './generic-transformers';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import { pushVariadicNumberArguments } from './generic-transformers';
|
||||
|
||||
export function transformArguments(slots: number | Array<number>): RedisCommandArguments {
|
||||
return pushVerdictNumberArguments(
|
||||
['CLUSTER', 'ADDSLOTS'],
|
||||
slots
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(slots: number | Array<number>) {
|
||||
return pushVariadicNumberArguments(
|
||||
['CLUSTER', 'ADDSLOTS'],
|
||||
slots
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): string;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import { pushSlotRangesArguments, SlotRange } from './generic-transformers';
|
||||
|
||||
export function transformArguments(
|
||||
ranges: SlotRange | Array<SlotRange>
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(ranges: SlotRange | Array<SlotRange>) {
|
||||
return pushSlotRangesArguments(
|
||||
['CLUSTER', 'ADDSLOTSRANGE'],
|
||||
ranges
|
||||
['CLUSTER', 'ADDSLOTSRANGE'],
|
||||
ranges
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CLUSTER', 'BUMPEPOCH'];
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): 'BUMPED' | 'STILL';
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLUSTER', 'BUMPEPOCH'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'BUMPED' | 'STILL'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
export function transformArguments(nodeId: string): Array<string> {
|
||||
return ['CLUSTER', 'COUNT-FAILURE-REPORTS', nodeId];
|
||||
}
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(nodeId: RedisArgument) {
|
||||
return ['CLUSTER', 'COUNT-FAILURE-REPORTS', nodeId];
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
export function transformArguments(slot: number): Array<string> {
|
||||
return ['CLUSTER', 'COUNTKEYSINSLOT', slot.toString()];
|
||||
}
|
||||
import { NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(slot: number) {
|
||||
return ['CLUSTER', 'COUNT-FAILURE-REPORTS', slot.toString()];
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { pushVerdictNumberArguments } from './generic-transformers';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import { pushVariadicNumberArguments } from './generic-transformers';
|
||||
|
||||
export function transformArguments(slots: number | Array<number>): RedisCommandArguments {
|
||||
return pushVerdictNumberArguments(
|
||||
['CLUSTER', 'DELSLOTS'],
|
||||
slots
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(slots: number | Array<number>) {
|
||||
return pushVariadicNumberArguments(
|
||||
['CLUSTER', 'DELSLOTS'],
|
||||
slots
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import { pushSlotRangesArguments, SlotRange } from './generic-transformers';
|
||||
|
||||
export function transformArguments(
|
||||
ranges: SlotRange | Array<SlotRange>
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(ranges: SlotRange | Array<SlotRange>) {
|
||||
return pushSlotRangesArguments(
|
||||
['CLUSTER', 'DELSLOTSRANGE'],
|
||||
ranges
|
||||
['CLUSTER', 'DELSLOTSRANGE'],
|
||||
ranges
|
||||
);
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,16 +1,22 @@
|
||||
export enum FailoverModes {
|
||||
FORCE = 'FORCE',
|
||||
TAKEOVER = 'TAKEOVER'
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(mode?: FailoverModes): Array<string> {
|
||||
export const FAILOVER_MODES = {
|
||||
FORCE: 'FORCE',
|
||||
TAKEOVER: 'TAKEOVER'
|
||||
} as const;
|
||||
|
||||
export type FailoverModes = typeof FAILOVER_MODES[keyof typeof FAILOVER_MODES];
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(mode?: FailoverModes) {
|
||||
const args = ['CLUSTER', 'FAILOVER'];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CLUSTER', 'FLUSHSLOTS'];
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLUSTER', 'FLUSHSLOTS'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
export function transformArguments(nodeId: string): Array<string> {
|
||||
return ['CLUSTER', 'FORGET', nodeId];
|
||||
}
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(nodeId: RedisArgument) {
|
||||
return ['CLUSTER', 'FORGET', nodeId];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
export function transformArguments(slot: number, count: number): Array<string> {
|
||||
return ['CLUSTER', 'GETKEYSINSLOT', slot.toString(), count.toString()];
|
||||
}
|
||||
import { ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): Array<string>;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(slot: number, count: number) {
|
||||
return ['CLUSTER', 'GETKEYSINSLOT', slot.toString(), count.toString()];
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
export function transformArguments(key: string): Array<string> {
|
||||
return ['CLUSTER', 'KEYSLOT', key];
|
||||
}
|
||||
import { Command, NumberReply, RedisArgument } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
transformArguments(key: RedisArgument) {
|
||||
return ['CLUSTER', 'KEYSLOT', key];
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
export function transformArguments(ip: string, port: number): Array<string> {
|
||||
return ['CLUSTER', 'MEET', ip, port.toString()];
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
export default {
|
||||
transformArguments(host: string, port: number) {
|
||||
return ['CLUSTER', 'MEET', host, port.toString()];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CLUSTER', 'MYID'];
|
||||
}
|
||||
import { BlobStringReply, Command } from "../RESP/types";
|
||||
|
||||
export declare function transformReply(): string;
|
||||
export default {
|
||||
transformArguments() {
|
||||
return ['CLUSTER', 'MYID'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
export function transformArguments(nodeId: string): Array<string> {
|
||||
return ['CLUSTER', 'REPLICATE', nodeId];
|
||||
}
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
export default {
|
||||
transformArguments(nodeId: RedisArgument) {
|
||||
return ['CLUSTER', 'REPLICATE', nodeId];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,46 +1,39 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { NumberReply, ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
return ['CLUSTER', 'SLOTS'];
|
||||
}
|
||||
type RawNode = [
|
||||
host: BlobStringReply,
|
||||
port: NumberReply,
|
||||
id: BlobStringReply
|
||||
];
|
||||
|
||||
type ClusterSlotsRawNode = [ip: string, port: number, id: string];
|
||||
|
||||
type ClusterSlotsRawReply = Array<[
|
||||
from: number,
|
||||
to: number,
|
||||
master: ClusterSlotsRawNode,
|
||||
...replicas: Array<ClusterSlotsRawNode>
|
||||
type ClusterSlotsRawReply = ArrayReply<[
|
||||
from: NumberReply,
|
||||
to: NumberReply,
|
||||
master: RawNode,
|
||||
...replicas: Array<RawNode>
|
||||
]>;
|
||||
|
||||
export interface ClusterSlotsNode {
|
||||
ip: string;
|
||||
port: number;
|
||||
id: string;
|
||||
};
|
||||
export type ClusterSlotsNode = ReturnType<typeof transformNode>;
|
||||
|
||||
export type ClusterSlotsReply = Array<{
|
||||
from: number;
|
||||
to: number;
|
||||
master: ClusterSlotsNode;
|
||||
replicas: Array<ClusterSlotsNode>;
|
||||
}>;
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['CLUSTER', 'SLOTS'];
|
||||
},
|
||||
transformReply(reply: ClusterSlotsRawReply) {
|
||||
return reply.map(([from, to, master, ...replicas]) => ({
|
||||
from,
|
||||
to,
|
||||
master: transformNode(master),
|
||||
replicas: replicas.map(transformNode)
|
||||
}));
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
||||
export function transformReply(reply: ClusterSlotsRawReply): ClusterSlotsReply {
|
||||
return reply.map(([from, to, master, ...replicas]) => {
|
||||
return {
|
||||
from,
|
||||
to,
|
||||
master: transformNode(master),
|
||||
replicas: replicas.map(transformNode)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function transformNode([ip, port, id]: ClusterSlotsRawNode): ClusterSlotsNode {
|
||||
return {
|
||||
ip,
|
||||
port,
|
||||
id
|
||||
};
|
||||
function transformNode([host, port, id ]: RawNode) {
|
||||
return {
|
||||
host,
|
||||
port,
|
||||
id
|
||||
};
|
||||
}
|
||||
|
@@ -1,5 +1,10 @@
|
||||
export function transformArguments(parameter: string): Array<string> {
|
||||
return ['CONFIG', 'GET', parameter];
|
||||
}
|
||||
import { RedisArgument, Command } from '../RESP/types';
|
||||
import { transformTuplesReply } from './generic-transformers';
|
||||
|
||||
export { transformTuplesReply as transformReply } from './generic-transformers';
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(parameter: RedisArgument) {
|
||||
return ['CONFIG', 'GET', parameter];
|
||||
},
|
||||
transformReply: transformTuplesReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CONFIG', 'RESETSTAT'];
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): string;
|
||||
export default {
|
||||
transformArguments() {
|
||||
return ['CONFIG', 'RESETSTAT'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CONFIG', 'REWRITE'];
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export declare function transformReply(): string;
|
||||
export default {
|
||||
transformArguments() {
|
||||
return ['CONFIG', 'REWRITE'];
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,23 +1,24 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command, RedisArgument } from '../RESP/types';
|
||||
|
||||
type SingleParameter = [parameter: RedisCommandArgument, value: RedisCommandArgument];
|
||||
type SingleParameter = [parameter: RedisArgument, value: RedisArgument];
|
||||
|
||||
type MultipleParameters = [config: Record<string, RedisCommandArgument>];
|
||||
type MultipleParameters = [config: Record<string, RedisArgument>];
|
||||
|
||||
export function transformArguments(
|
||||
export default {
|
||||
transformArguments(
|
||||
...[parameterOrConfig, value]: SingleParameter | MultipleParameters
|
||||
): RedisCommandArguments {
|
||||
const args: RedisCommandArguments = ['CONFIG', 'SET'];
|
||||
|
||||
if (typeof parameterOrConfig === 'string') {
|
||||
args.push(parameterOrConfig, value!);
|
||||
) {
|
||||
const args: Array<RedisArgument> = ['CONFIG', 'SET'];
|
||||
|
||||
if (typeof parameterOrConfig === 'string' || Buffer.isBuffer(parameterOrConfig)) {
|
||||
args.push(parameterOrConfig, value!);
|
||||
} else {
|
||||
for (const [key, value] of Object.entries(parameterOrConfig)) {
|
||||
args.push(key, value);
|
||||
}
|
||||
for (const [key, value] of Object.entries(parameterOrConfig)) {
|
||||
args.push(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): string;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,28 +1,24 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
interface CopyCommandOptions {
|
||||
destinationDb?: number;
|
||||
replace?: boolean;
|
||||
export interface CopyCommandOptions {
|
||||
DB?: number;
|
||||
REPLACE?: boolean;
|
||||
}
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
source: RedisCommandArgument,
|
||||
destination: RedisCommandArgument,
|
||||
options?: CopyCommandOptions
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
transformArguments(source: RedisArgument, destination: RedisArgument, options?: CopyCommandOptions) {
|
||||
const args = ['COPY', source, destination];
|
||||
|
||||
if (options?.destinationDb) {
|
||||
args.push('DB', options.destinationDb.toString());
|
||||
if (options?.DB) {
|
||||
args.push('DB', options.DB.toString());
|
||||
}
|
||||
|
||||
if (options?.replace) {
|
||||
args.push('REPLACE');
|
||||
if (options?.REPLACE) {
|
||||
args.push('REPLACE');
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,9 @@
|
||||
export const IS_READ_ONLY = true;
|
||||
import { NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments() {
|
||||
return ['DBSIZE'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: RedisCommandArgument): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
transformArguments(key: RedisArgument) {
|
||||
return ['DECR', key];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,12 +1,9 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
decrement: number
|
||||
): RedisCommandArguments {
|
||||
return ['DECRBY', key, decrement.toString()];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
transformArguments(key: RedisArgument, decrement: number) {
|
||||
return ['DECR', key, decrement.toString()];
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,12 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
import { pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
keys: RedisCommandArgument | Array<RedisCommandArgument>
|
||||
): RedisCommandArguments {
|
||||
return pushVerdictArguments(['DEL'], keys);
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
transformArguments(keys: RedisArgument | Array<RedisArgument>) {
|
||||
return pushVariadicArguments(['DEL'], keys);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import { RedisCommandArgument } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
export default {
|
||||
transformArguments() {
|
||||
return ['DISCARD'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: RedisCommandArgument): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument) {
|
||||
return ['DUMP', key];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(message: RedisCommandArgument): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(message: RedisArgument) {
|
||||
return ['ECHO', message];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,14 +1,11 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArguments } from './generic-transformers';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
import { pushVariadicArguments } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
keys: RedisCommandArgument | Array<RedisCommandArgument>
|
||||
): RedisCommandArguments {
|
||||
return pushVerdictArguments(['EXISTS'], keys);
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(keys: RedisArgument | Array<RedisArgument>) {
|
||||
return pushVariadicArguments(['EXISTS'], keys);
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
seconds: number,
|
||||
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||
): RedisCommandArguments {
|
||||
) {
|
||||
const args = ['EXPIRE', key, seconds.toString()];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,24 +1,21 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
import { transformEXAT } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
timestamp: number | Date,
|
||||
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||
): RedisCommandArguments {
|
||||
const args = [
|
||||
'EXPIREAT',
|
||||
key,
|
||||
transformEXAT(timestamp)
|
||||
];
|
||||
) {
|
||||
const args = ['EXPIRE', key, transformEXAT(timestamp)];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, NumberReply, Command } from '../RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: RedisCommandArgument): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument) {
|
||||
return ['EXPIRETIME', key];
|
||||
}
|
||||
|
||||
export declare function transformReply(): number;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,33 +1,36 @@
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
interface FailoverOptions {
|
||||
TO?: {
|
||||
host: string;
|
||||
port: number;
|
||||
FORCE?: true;
|
||||
};
|
||||
ABORT?: true;
|
||||
TIMEOUT?: number;
|
||||
TO?: {
|
||||
host: string;
|
||||
port: number;
|
||||
FORCE?: true;
|
||||
};
|
||||
ABORT?: true;
|
||||
TIMEOUT?: number;
|
||||
}
|
||||
|
||||
export function transformArguments(options?: FailoverOptions): Array<string> {
|
||||
export default {
|
||||
transformArguments(options?: FailoverOptions) {
|
||||
const args = ['FAILOVER'];
|
||||
|
||||
if (options?.TO) {
|
||||
args.push('TO', options.TO.host, options.TO.port.toString());
|
||||
args.push('TO', options.TO.host, options.TO.port.toString());
|
||||
|
||||
if (options.TO.FORCE) {
|
||||
args.push('FORCE');
|
||||
}
|
||||
if (options.TO.FORCE) {
|
||||
args.push('FORCE');
|
||||
}
|
||||
}
|
||||
|
||||
if (options?.ABORT) {
|
||||
args.push('ABORT');
|
||||
args.push('ABORT');
|
||||
}
|
||||
|
||||
if (options?.TIMEOUT) {
|
||||
args.push('TIMEOUT', options.TIMEOUT.toString());
|
||||
args.push('TIMEOUT', options.TIMEOUT.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): string;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,16 +1,21 @@
|
||||
export enum RedisFlushModes {
|
||||
ASYNC = 'ASYNC',
|
||||
SYNC = 'SYNC'
|
||||
}
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(mode?: RedisFlushModes): Array<string> {
|
||||
export const REDIS_FLUSH_MODES = {
|
||||
ASYNC: 'ASYNC',
|
||||
SYNC: 'SYNC'
|
||||
} as const;
|
||||
|
||||
export type RedisFlushModes = typeof REDIS_FLUSH_MODES[keyof typeof REDIS_FLUSH_MODES];
|
||||
|
||||
export default {
|
||||
transformArguments(mode?: RedisFlushModes) {
|
||||
const args = ['FLUSHALL'];
|
||||
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): string;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,15 @@
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import { RedisFlushModes } from './FLUSHALL';
|
||||
|
||||
export function transformArguments(mode?: RedisFlushModes): Array<string> {
|
||||
export default {
|
||||
transformArguments(mode?: RedisFlushModes) {
|
||||
const args = ['FLUSHDB'];
|
||||
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): string;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(library: string): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
transformArguments(library: RedisArgument) {
|
||||
return ['FUNCTION', 'DELETE', library];
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
export function transformArguments(): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
transformArguments() {
|
||||
return ['FUNCTION', 'DUMP'];
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,13 +1,17 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { SimpleStringReply, Command } from '../RESP/types';
|
||||
import { RedisFlushModes } from './FLUSHALL';
|
||||
|
||||
export function transformArguments(mode?: 'ASYNC' | 'SYNC'): RedisCommandArguments {
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
FIRST_KEY_INDEX: undefined,
|
||||
transformArguments(mode?: RedisFlushModes) {
|
||||
const args = ['FUNCTION', 'FLUSH'];
|
||||
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
} as const satisfies Command;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user