You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Support SORT_RO (#2041)
* Support SORT_RO * move pushSortReadOnlyArgs and SortReadOnlyOptions to generic-transformers * clean code Co-authored-by: leibale <leibale1998@gmail.com>
This commit is contained in:
96
packages/client/lib/commands/SORT_STORE.spec.ts
Normal file
96
packages/client/lib/commands/SORT_STORE.spec.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './SORT_STORE';
|
||||
|
||||
describe('SORT STORE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('source', '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 => {
|
||||
assert.equal(
|
||||
await client.sortStore('source', 'destination'),
|
||||
0
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
Reference in New Issue
Block a user