You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
more commands
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './NUMINCRBY';
|
||||
import NUMINCRBY from './NUMINCRBY';
|
||||
|
||||
describe('NUMINCRBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 1),
|
||||
['JSON.NUMINCRBY', 'key', '$', '1']
|
||||
);
|
||||
});
|
||||
describe('JSON.NUMINCRBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
NUMINCRBY.transformArguments('key', '$', 1),
|
||||
['JSON.NUMINCRBY', 'key', '$', '1']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.numIncrBy', async client => {
|
||||
await client.json.set('key', '$', 0);
|
||||
testUtils.testWithClient('client.json.numIncrBy', async client => {
|
||||
await client.json.set('key', '$', 0);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.json.numIncrBy('key', '$', 1),
|
||||
[1]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
assert.deepEqual(
|
||||
await client.json.numIncrBy('key', '$', 1),
|
||||
[1]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,7 +1,10 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
import { RedisArgument, Command, ArrayReply, NumberReply, DoubleReply, NullReply } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export function transformArguments(key: string, path: string, by: number): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
|
||||
return ['JSON.NUMINCRBY', key, path, by.toString()];
|
||||
}
|
||||
|
||||
export { transformNumbersReply as transformReply } from '.';
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<NumberReply | DoubleReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,21 +1,21 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './NUMMULTBY';
|
||||
import NUMMULTBY from './NUMMULTBY';
|
||||
|
||||
describe('NUMMULTBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 2),
|
||||
['JSON.NUMMULTBY', 'key', '$', '2']
|
||||
);
|
||||
});
|
||||
describe('JSON.NUMMULTBY', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
NUMMULTBY.transformArguments('key', '$', 2),
|
||||
['JSON.NUMMULTBY', 'key', '$', '2']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.numMultBy', async client => {
|
||||
await client.json.set('key', '$', 1);
|
||||
testUtils.testWithClient('client.json.numMultBy', async client => {
|
||||
await client.json.set('key', '$', 1);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.json.numMultBy('key', '$', 2),
|
||||
[2]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
assert.deepEqual(
|
||||
await client.json.numMultBy('key', '$', 2),
|
||||
[2]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,7 +1,10 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
import { RedisArgument, Command, ArrayReply, NumberReply, DoubleReply, NullReply } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export function transformArguments(key: string, path: string, by: number): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, by: number) {
|
||||
return ['JSON.NUMMULTBY', key, path, by.toString()];
|
||||
}
|
||||
|
||||
export { transformNumbersReply as transformReply } from '.';
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<NumberReply | DoubleReply | NullReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,28 +1,28 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './OBJKEYS';
|
||||
import OBJKEYS from './OBJKEYS';
|
||||
|
||||
describe('OBJKEYS', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key'),
|
||||
['JSON.OBJKEYS', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$'),
|
||||
['JSON.OBJKEYS', 'key', '$']
|
||||
);
|
||||
});
|
||||
describe('JSON.OBJKEYS', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without path', () => {
|
||||
assert.deepEqual(
|
||||
OBJKEYS.transformArguments('key'),
|
||||
['JSON.OBJKEYS', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
// testUtils.testWithClient('client.json.objKeys', async client => {
|
||||
// assert.deepEqual(
|
||||
// await client.json.objKeys('key', '$'),
|
||||
// [null]
|
||||
// );
|
||||
// }, GLOBAL.SERVERS.OPEN);
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
OBJKEYS.transformArguments('key', '$'),
|
||||
['JSON.OBJKEYS', 'key', '$']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.objKeys', async client => {
|
||||
assert.deepEqual(
|
||||
await client.json.objKeys('key', '$'),
|
||||
[null]
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,13 +1,18 @@
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export function transformArguments(key: string, path?: string): Array<string> {
|
||||
type ReplyItem = ArrayReply<BlobStringReply> | NullReply;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path?: RedisArgument) {
|
||||
const args = ['JSON.OBJKEYS', key];
|
||||
|
||||
if (path) {
|
||||
args.push(path);
|
||||
args.push(path);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<string> | null | Array<Array<string> | null>;
|
||||
},
|
||||
transformReply: undefined as unknown as () => ReplyItem | ArrayReply<ReplyItem>
|
||||
} as const satisfies Command;
|
||||
|
@@ -1,35 +1,35 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './SET';
|
||||
import SET from './SET';
|
||||
|
||||
describe('SET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 'json'),
|
||||
['JSON.SET', 'key', '$', '"json"']
|
||||
);
|
||||
});
|
||||
|
||||
it('NX', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 'json', { NX: true }),
|
||||
['JSON.SET', 'key', '$', '"json"', 'NX']
|
||||
);
|
||||
});
|
||||
|
||||
it('XX', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 'json', { XX: true }),
|
||||
['JSON.SET', 'key', '$', '"json"', 'XX']
|
||||
);
|
||||
});
|
||||
describe('JSON.SET', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
SET.transformArguments('key', '$', 'json'),
|
||||
['JSON.SET', 'key', '$', '"json"']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.mGet', async client => {
|
||||
assert.equal(
|
||||
await client.json.set('key', '$', 'json'),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
it('NX', () => {
|
||||
assert.deepEqual(
|
||||
SET.transformArguments('key', '$', 'json', { NX: true }),
|
||||
['JSON.SET', 'key', '$', '"json"', 'NX']
|
||||
);
|
||||
});
|
||||
|
||||
it('XX', () => {
|
||||
assert.deepEqual(
|
||||
SET.transformArguments('key', '$', 'json', { XX: true }),
|
||||
['JSON.SET', 'key', '$', '"json"', 'XX']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.json.set', async client => {
|
||||
assert.equal(
|
||||
await client.json.set('key', '$', 'json'),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,25 +1,27 @@
|
||||
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisJSON, transformRedisJsonArgument } from '.';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
interface NX {
|
||||
NX: true;
|
||||
export interface NX {
|
||||
NX: true;
|
||||
}
|
||||
|
||||
interface XX {
|
||||
XX: true;
|
||||
export interface XX {
|
||||
XX: true;
|
||||
}
|
||||
|
||||
export function transformArguments(key: string, path: string, json: RedisJSON, options?: NX | XX): Array<string> {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(key: RedisArgument, path: RedisArgument, json: RedisJSON, options?: NX | XX) {
|
||||
const args = ['JSON.SET', key, path, transformRedisJsonArgument(json)];
|
||||
|
||||
if ((<NX>options)?.NX) {
|
||||
args.push('NX');
|
||||
args.push('NX');
|
||||
} else if ((<XX>options)?.XX) {
|
||||
args.push('XX');
|
||||
args.push('XX');
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK' | null;
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'> | NullReply
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user