1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-04-27 19:17:11 -04:00
parent ab3973aca3
commit 8d615e99ed
16 changed files with 490 additions and 431 deletions

View File

@@ -1,27 +1,27 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import { transformArguments } from './SHUTDOWN'; // import { transformArguments } from './SHUTDOWN';
describe('SHUTDOWN', () => { // describe('SHUTDOWN', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments(), // transformArguments(),
['SHUTDOWN'] // ['SHUTDOWN']
); // );
}); // });
it('NOSAVE', () => { // it('NOSAVE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('NOSAVE'), // transformArguments('NOSAVE'),
['SHUTDOWN', 'NOSAVE'] // ['SHUTDOWN', 'NOSAVE']
); // );
}); // });
it('SAVE', () => { // it('SAVE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('SAVE'), // transformArguments('SAVE'),
['SHUTDOWN', 'SAVE'] // ['SHUTDOWN', 'SAVE']
); // );
}); // });
}); // });
}); // });

View File

@@ -1,11 +1,11 @@
export function transformArguments(mode?: 'NOSAVE' | 'SAVE'): Array<string> { // export function transformArguments(mode?: 'NOSAVE' | 'SAVE'): Array<string> {
const args = ['SHUTDOWN']; // const args = ['SHUTDOWN'];
if (mode) { // if (mode) {
args.push(mode); // args.push(mode);
} // }
return args; // return args;
} // }
export declare function transformReply(): void; // export declare function transformReply(): void;

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SINTER'; import SINTER from './SINTER';
describe('SINTER', () => { describe('SINTER', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), SINTER.transformArguments('key'),
['SINTER', 'key'] ['SINTER', 'key']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['SINTER', '1', '2']
);
});
}); });
testUtils.testWithClient('client.sInter', async client => { it('array', () => {
assert.deepEqual( assert.deepEqual(
await client.sInter('key'), SINTER.transformArguments(['1', '2']),
[] ['SINTER', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('sInter', async client => {
assert.deepEqual(
await client.sInter('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,30 +1,42 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SINTERCARD'; import SINTERCARD from './SINTERCARD';
describe('SINTERCARD', () => { describe('SINTERCARD', () => {
testUtils.isVersionGreaterThanHook([7]); testUtils.isVersionGreaterThanHook([7]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(['1', '2']), SINTERCARD.transformArguments(['1', '2']),
['SINTERCARD', '2', '1', '2'] ['SINTERCARD', '2', '1', '2']
); );
});
it('with limit', () => {
assert.deepEqual(
transformArguments(['1', '2'], 1),
['SINTERCARD', '2', '1', '2', 'LIMIT', '1']
);
});
}); });
testUtils.testWithClient('client.sInterCard', async client => { it('with limit (backwards compatibility)', () => {
assert.deepEqual( assert.deepEqual(
await client.sInterCard('key'), SINTERCARD.transformArguments(['1', '2'], 1),
0 ['SINTERCARD', '2', '1', '2', 'LIMIT', '1']
); );
}, GLOBAL.SERVERS.OPEN); });
it('with LIMIT', () => {
assert.deepEqual(
SINTERCARD.transformArguments(['1', '2'], {
LIMIT: 1
}),
['SINTERCARD', '2', '1', '2', 'LIMIT', '1']
);
});
});
testUtils.testAll('sInterCard', async client => {
assert.deepEqual(
await client.sInterCard('key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,5 +1,5 @@
import { RedisArgument, NumberReply, Command } from '../RESP/types'; import { RedisArgument, NumberReply, Command } from '../RESP/types';
import { pushVariadicArguments } from './generic-transformers'; import { pushVariadicArgument } from './generic-transformers';
export interface SInterCardOptions { export interface SInterCardOptions {
LIMIT?: number; LIMIT?: number;
@@ -12,7 +12,7 @@ export default {
keys: Array<RedisArgument> | RedisArgument, keys: Array<RedisArgument> | RedisArgument,
options?: SInterCardOptions | number // `number` for backwards compatibility options?: SInterCardOptions | number // `number` for backwards compatibility
) { ) {
const args = pushVariadicArguments(['SINTERCARD'], keys); const args = pushVariadicArgument(['SINTERCARD'], keys);
if (typeof options === 'number') { // backwards compatibility if (typeof options === 'number') { // backwards compatibility
args.push('LIMIT', options.toString()); args.push('LIMIT', options.toString());

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SINTERSTORE'; import SINTERSTORE from './SINTERSTORE';
describe('SINTERSTORE', () => { describe('SINTERSTORE', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('destination', 'key'), SINTERSTORE.transformArguments('destination', 'key'),
['SINTERSTORE', 'destination', 'key'] ['SINTERSTORE', 'destination', 'key']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments('destination', ['1', '2']),
['SINTERSTORE', 'destination', '1', '2']
);
});
}); });
testUtils.testWithClient('client.sInterStore', async client => { it('array', () => {
assert.equal( assert.deepEqual(
await client.sInterStore('destination', 'key'), SINTERSTORE.transformArguments('destination', ['1', '2']),
0 ['SINTERSTORE', 'destination', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('sInterStore', async client => {
assert.equal(
await client.sInterStore('{tag}destination', '{tag}key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SISMEMBER'; import SISMEMBER from './SISMEMBER';
describe('SISMEMBER', () => { describe('SISMEMBER', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), SISMEMBER.transformArguments('key', 'member'),
['SISMEMBER', 'key', 'member'] ['SISMEMBER', 'key', 'member']
); );
}); });
testUtils.testWithClient('client.sIsMember', async client => { testUtils.testAll('sIsMember', async client => {
assert.equal( assert.equal(
await client.sIsMember('key', 'member'), await client.sIsMember('key', 'member'),
false 0
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SMEMBERS'; import SMEMBERS from './SMEMBERS';
describe('SMEMBERS', () => { describe('SMEMBERS', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), SMEMBERS.transformArguments('key'),
['SMEMBERS', 'key'] ['SMEMBERS', 'key']
); );
}); });
testUtils.testWithClient('client.sMembers', async client => { testUtils.testAll('sMembers', async client => {
assert.deepEqual( assert.deepEqual(
await client.sMembers('key'), await client.sMembers('key'),
[] []
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,21 +1,24 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SMISMEMBER'; import SMISMEMBER from './SMISMEMBER';
describe('SMISMEMBER', () => { describe('SMISMEMBER', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', ['1', '2']), SMISMEMBER.transformArguments('key', ['1', '2']),
['SMISMEMBER', 'key', '1', '2'] ['SMISMEMBER', 'key', '1', '2']
); );
}); });
testUtils.testWithClient('client.smIsMember', async client => { testUtils.testAll('smIsMember', async client => {
assert.deepEqual( assert.deepEqual(
await client.smIsMember('key', ['1', '2']), await client.smIsMember('key', ['1', '2']),
[false, false] [0, 0]
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SMOVE'; // import { transformArguments } from './SMOVE';
describe('SMOVE', () => { // describe('SMOVE', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('source', 'destination', 'member'), // transformArguments('source', 'destination', 'member'),
['SMOVE', 'source', 'destination', 'member'] // ['SMOVE', 'source', 'destination', 'member']
); // );
}); // });
testUtils.testWithClient('client.sMove', async client => { // testUtils.testWithClient('client.sMove', async client => {
assert.equal( // assert.equal(
await client.sMove('source', 'destination', 'member'), // await client.sMove('source', 'destination', 'member'),
false // false
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,96 +1,99 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SORT'; import SORT from './SORT';
describe('SORT', () => { describe('SORT', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), SORT.transformArguments('key'),
['SORT', 'key'] ['SORT', 'key']
); );
});
it('with BY', () => {
assert.deepEqual(
transformArguments('key', {
BY: 'pattern'
}),
['SORT', 'key', 'BY', 'pattern']
);
});
it('with LIMIT', () => {
assert.deepEqual(
transformArguments('key', {
LIMIT: {
offset: 0,
count: 1
}
}),
['SORT', 'key', 'LIMIT', '0', '1']
);
});
describe('with GET', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key', {
GET: 'pattern'
}),
['SORT', 'key', 'GET', 'pattern']
);
});
it('array', () => {
assert.deepEqual(
transformArguments('key', {
GET: ['1', '2']
}),
['SORT', 'key', 'GET', '1', 'GET', '2']
);
});
});
it('with DIRECTION', () => {
assert.deepEqual(
transformArguments('key', {
DIRECTION: 'ASC'
}),
['SORT', 'key', 'ASC']
);
});
it('with ALPHA', () => {
assert.deepEqual(
transformArguments('key', {
ALPHA: true
}),
['SORT', 'key', 'ALPHA']
);
});
it('with BY, LIMIT, GET, DIRECTION, ALPHA', () => {
assert.deepEqual(
transformArguments('key', {
BY: 'pattern',
LIMIT: {
offset: 0,
count: 1
},
GET: 'pattern',
DIRECTION: 'ASC',
ALPHA: true
}),
['SORT', 'key', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA']
);
});
}); });
testUtils.testWithClient('client.sort', async client => { it('with BY', () => {
assert.deepEqual(
SORT.transformArguments('key', {
BY: 'pattern'
}),
['SORT', 'key', 'BY', 'pattern']
);
});
it('with LIMIT', () => {
assert.deepEqual(
SORT.transformArguments('key', {
LIMIT: {
offset: 0,
count: 1
}
}),
['SORT', 'key', 'LIMIT', '0', '1']
);
});
describe('with GET', () => {
it('string', () => {
assert.deepEqual( assert.deepEqual(
await client.sort('key'), SORT.transformArguments('key', {
[] GET: 'pattern'
}),
['SORT', 'key', 'GET', 'pattern']
); );
}, GLOBAL.SERVERS.OPEN); });
it('array', () => {
assert.deepEqual(
SORT.transformArguments('key', {
GET: ['1', '2']
}),
['SORT', 'key', 'GET', '1', 'GET', '2']
);
});
});
it('with DIRECTION', () => {
assert.deepEqual(
SORT.transformArguments('key', {
DIRECTION: 'ASC'
}),
['SORT', 'key', 'ASC']
);
});
it('with ALPHA', () => {
assert.deepEqual(
SORT.transformArguments('key', {
ALPHA: true
}),
['SORT', 'key', 'ALPHA']
);
});
it('with BY, LIMIT, GET, DIRECTION, ALPHA', () => {
assert.deepEqual(
SORT.transformArguments('key', {
BY: 'pattern',
LIMIT: {
offset: 0,
count: 1
},
GET: 'pattern',
DIRECTION: 'ASC',
ALPHA: true
}),
['SORT', 'key', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA']
);
});
});
testUtils.testAll('sort', async client => {
assert.deepEqual(
await client.sort('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,21 +1,22 @@
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types'; import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
export interface SortOptions { export interface SortOptions {
BY?: string; BY?: RedisArgument;
LIMIT?: { LIMIT?: {
offset: number; offset: number;
count: number; count: number;
}, };
GET?: string | Array<string>; GET?: RedisArgument | Array<RedisArgument>;
DIRECTION?: 'ASC' | 'DESC'; DIRECTION?: 'ASC' | 'DESC';
ALPHA?: true; ALPHA?: boolean;
} }
export function transformSortArguments( export function transformSortArguments(
command: RedisArgument, command: RedisArgument,
key: RedisArgument,
options?: SortOptions options?: SortOptions
) { ) {
const args = [command]; const args: Array<RedisArgument> = [command, key];
if (options?.BY) { if (options?.BY) {
args.push('BY', options.BY); args.push('BY', options.BY);
@@ -30,12 +31,12 @@ export function transformSortArguments(
} }
if (options?.GET) { if (options?.GET) {
if (typeof options.GET === 'string') { if (Array.isArray(options.GET)) {
args.push('GET', options.GET);
} else {
for (const pattern of options.GET) { for (const pattern of options.GET) {
args.push('GET', pattern); args.push('GET', pattern);
} }
} else {
args.push('GET', options.GET);
} }
} }

View File

@@ -1,98 +1,101 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SORT_RO'; import SORT_RO from './SORT_RO';
describe('SORT_RO', () => { describe('SORT_RO', () => {
testUtils.isVersionGreaterThanHook([7]); testUtils.isVersionGreaterThanHook([7]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), SORT_RO.transformArguments('key'),
['SORT_RO', 'key'] ['SORT_RO', 'key']
); );
});
it('with BY', () => {
assert.deepEqual(
transformArguments('key', {
BY: 'pattern'
}),
['SORT_RO', 'key', 'BY', 'pattern']
);
});
it('with LIMIT', () => {
assert.deepEqual(
transformArguments('key', {
LIMIT: {
offset: 0,
count: 1
}
}),
['SORT_RO', 'key', 'LIMIT', '0', '1']
);
});
describe('with GET', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key', {
GET: 'pattern'
}),
['SORT_RO', 'key', 'GET', 'pattern']
);
});
it('array', () => {
assert.deepEqual(
transformArguments('key', {
GET: ['1', '2']
}),
['SORT_RO', 'key', 'GET', '1', 'GET', '2']
);
});
});
it('with DIRECTION', () => {
assert.deepEqual(
transformArguments('key', {
DIRECTION: 'ASC'
}),
['SORT_RO', 'key', 'ASC']
);
});
it('with ALPHA', () => {
assert.deepEqual(
transformArguments('key', {
ALPHA: true
}),
['SORT_RO', 'key', 'ALPHA']
);
});
it('with BY, LIMIT, GET, DIRECTION, ALPHA', () => {
assert.deepEqual(
transformArguments('key', {
BY: 'pattern',
LIMIT: {
offset: 0,
count: 1
},
GET: 'pattern',
DIRECTION: 'ASC',
ALPHA: true,
}),
['SORT_RO', 'key', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA']
);
});
}); });
testUtils.testWithClient('client.sortRo', async client => { it('with BY', () => {
assert.deepEqual(
SORT_RO.transformArguments('key', {
BY: 'pattern'
}),
['SORT_RO', 'key', 'BY', 'pattern']
);
});
it('with LIMIT', () => {
assert.deepEqual(
SORT_RO.transformArguments('key', {
LIMIT: {
offset: 0,
count: 1
}
}),
['SORT_RO', 'key', 'LIMIT', '0', '1']
);
});
describe('with GET', () => {
it('string', () => {
assert.deepEqual( assert.deepEqual(
await client.sortRo('key'), SORT_RO.transformArguments('key', {
[] GET: 'pattern'
}),
['SORT_RO', 'key', 'GET', 'pattern']
); );
}, GLOBAL.SERVERS.OPEN); });
it('array', () => {
assert.deepEqual(
SORT_RO.transformArguments('key', {
GET: ['1', '2']
}),
['SORT_RO', 'key', 'GET', '1', 'GET', '2']
);
});
});
it('with DIRECTION', () => {
assert.deepEqual(
SORT_RO.transformArguments('key', {
DIRECTION: 'ASC'
}),
['SORT_RO', 'key', 'ASC']
);
});
it('with ALPHA', () => {
assert.deepEqual(
SORT_RO.transformArguments('key', {
ALPHA: true
}),
['SORT_RO', 'key', 'ALPHA']
);
});
it('with BY, LIMIT, GET, DIRECTION, ALPHA', () => {
assert.deepEqual(
SORT_RO.transformArguments('key', {
BY: 'pattern',
LIMIT: {
offset: 0,
count: 1
},
GET: 'pattern',
DIRECTION: 'ASC',
ALPHA: true,
}),
['SORT_RO', 'key', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA']
);
});
});
testUtils.testAll('client.sortRo', async client => {
assert.deepEqual(
await client.sortRo('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,96 +1,99 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SORT_STORE'; import SORT_STORE from './SORT_STORE';
describe('SORT STORE', () => { describe('SORT STORE', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('source', 'destination'), SORT_STORE.transformArguments('source', 'destination'),
['SORT', 'source', 'STORE', 'destination'] ['SORT', 'source', 'STORE', 'destination']
); );
});
it('with BY', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
BY: 'pattern'
}),
['SORT', 'source', 'BY', 'pattern', 'STORE', 'destination']
);
});
it('with LIMIT', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
LIMIT: {
offset: 0,
count: 1
}
}),
['SORT', 'source', 'LIMIT', '0', '1', 'STORE', 'destination']
);
});
describe('with GET', () => {
it('string', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
GET: 'pattern'
}),
['SORT', 'source', 'GET', 'pattern', 'STORE', 'destination']
);
});
it('array', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
GET: ['1', '2']
}),
['SORT', 'source', 'GET', '1', 'GET', '2', 'STORE', 'destination']
);
});
});
it('with DIRECTION', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
DIRECTION: 'ASC'
}),
['SORT', 'source', 'ASC', 'STORE', 'destination']
);
});
it('with ALPHA', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
ALPHA: true
}),
['SORT', 'source', 'ALPHA', 'STORE', 'destination']
);
});
it('with BY, LIMIT, GET, DIRECTION, ALPHA', () => {
assert.deepEqual(
transformArguments('source', 'destination', {
BY: 'pattern',
LIMIT: {
offset: 0,
count: 1
},
GET: 'pattern',
DIRECTION: 'ASC',
ALPHA: true
}),
['SORT', 'source', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA', 'STORE', 'destination']
);
});
}); });
testUtils.testWithClient('client.sortStore', async client => { it('with BY', () => {
assert.equal( assert.deepEqual(
await client.sortStore('source', 'destination'), SORT_STORE.transformArguments('source', 'destination', {
0 BY: 'pattern'
}),
['SORT', 'source', 'BY', 'pattern', 'STORE', 'destination']
);
});
it('with LIMIT', () => {
assert.deepEqual(
SORT_STORE.transformArguments('source', 'destination', {
LIMIT: {
offset: 0,
count: 1
}
}),
['SORT', 'source', 'LIMIT', '0', '1', 'STORE', 'destination']
);
});
describe('with GET', () => {
it('string', () => {
assert.deepEqual(
SORT_STORE.transformArguments('source', 'destination', {
GET: 'pattern'
}),
['SORT', 'source', 'GET', 'pattern', 'STORE', 'destination']
); );
}, GLOBAL.SERVERS.OPEN); });
it('array', () => {
assert.deepEqual(
SORT_STORE.transformArguments('source', 'destination', {
GET: ['1', '2']
}),
['SORT', 'source', 'GET', '1', 'GET', '2', 'STORE', 'destination']
);
});
});
it('with DIRECTION', () => {
assert.deepEqual(
SORT_STORE.transformArguments('source', 'destination', {
DIRECTION: 'ASC'
}),
['SORT', 'source', 'ASC', 'STORE', 'destination']
);
});
it('with ALPHA', () => {
assert.deepEqual(
SORT_STORE.transformArguments('source', 'destination', {
ALPHA: true
}),
['SORT', 'source', 'ALPHA', 'STORE', 'destination']
);
});
it('with BY, LIMIT, GET, DIRECTION, ALPHA', () => {
assert.deepEqual(
SORT_STORE.transformArguments('source', 'destination', {
BY: 'pattern',
LIMIT: {
offset: 0,
count: 1
},
GET: 'pattern',
DIRECTION: 'ASC',
ALPHA: true
}),
['SORT', 'source', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA', 'STORE', 'destination']
);
});
});
testUtils.testAll('sortStore', async client => {
assert.equal(
await client.sortStore('{tag}source', '{tag}destination'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,5 +1,5 @@
import { RedisArgument, NumberReply, Command } from '../RESP/types'; import { RedisArgument, NumberReply, Command } from '../RESP/types';
import { SortOptions, transformSortArguments } from './SORT'; import SORT, { SortOptions } from './SORT';
export default { export default {
FIRST_KEY_INDEX: 1, FIRST_KEY_INDEX: 1,
@@ -9,7 +9,7 @@ export default {
destination: RedisArgument, destination: RedisArgument,
options?: SortOptions options?: SortOptions
) { ) {
const args = transformSortArguments(source, options); const args = SORT.transformArguments(source, options);
args.push('STORE', destination); args.push('STORE', destination);
return args; return args;
}, },

View File

@@ -103,7 +103,15 @@ import SET from './SET';
import SETEX from './SETEX'; import SETEX from './SETEX';
import SETNX from './SETNX'; import SETNX from './SETNX';
import SETRANGE from './SETRANGE'; import SETRANGE from './SETRANGE';
import SINTER from './SINTER';
import SINTERCARD from './SINTERCARD';
import SINTERSTORE from './SINTERSTORE';
import SISMEMBER from './SISMEMBER';
import SMEMBERS from './SMEMBERS'; import SMEMBERS from './SMEMBERS';
import SMISMEMBER from './SMISMEMBER';
import SORT_RO from './SORT_RO';
import SORT_STORE from './SORT_STORE';
import SORT from './SORT';
import SPUBLISH from './SPUBLISH'; import SPUBLISH from './SPUBLISH';
import SRANDMEMBER_COUNT from './SRANDMEMBER_COUNT'; import SRANDMEMBER_COUNT from './SRANDMEMBER_COUNT';
import SRANDMEMBER from './SRANDMEMBER'; import SRANDMEMBER from './SRANDMEMBER';
@@ -351,11 +359,25 @@ export default {
SETEX, SETEX,
setEx: SETEX, setEx: SETEX,
SETNX, SETNX,
setNx: SETNX, setNx: SETNX,
SETRANGE, SINTER,
setRange: SETRANGE, sInter: SINTER,
SINTERCARD,
sInterCard: SINTERCARD,
SINTERSTORE,
sInterStore: SINTERSTORE,
SISMEMBER,
sIsMember: SISMEMBER,
SMEMBERS, SMEMBERS,
sMembers: SMEMBERS, sMembers: SMEMBERS,
SMISMEMBER,
smIsMember: SMISMEMBER,
SORT_RO,
sortRo: SORT_RO,
SORT_STORE,
sortStore: SORT_STORE,
SORT,
sort: SORT,
SPUBLISH, SPUBLISH,
sPublish: SPUBLISH, sPublish: SPUBLISH,
SRANDMEMBER_COUNT, SRANDMEMBER_COUNT,