Skip to content

Commit d59254e

Browse files
committed
some commands
1 parent a6c0d1d commit d59254e

21 files changed

+291
-231
lines changed

docs/v4-to-v5.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ Some command arguments/replies have changed to align more closely to data types
8585
- `HRANDFIELD_COUNT_WITHVALUES`: `Record<BlobString, BlobString>` -> `Array<{ field: BlobString; value: BlobString; }>` (it can return duplicates).
8686
- `SCAN`, `HSCAN`, `SSCAN`, and `ZSCAN`: cursor type is `string` instead of `number`?
8787
- `HSETNX`: `boolean` -> `number` [^boolean-to-number]
88-
- `ZINTER`: instead of `client.ZINTER('11, { WEIGHTS: [1] })` use `client.ZINTER({ key: '1', weight: 1 }])`
88+
- `ZINTER`: instead of `client.ZINTER('key', { WEIGHTS: [1] })` use `client.ZINTER({ key: 'key', weight: 1 }])`
89+
- `ZINTER_WITHSCORES`: instead of `client.ZINTER_WITHSCORES('key', { WEIGHTS: [1] })` use `client.ZINTER_WITHSCORES({ key: 'key', weight: 1 }])`
90+
- `ZUNION`: instead of `client.ZUNION('key', { WEIGHTS: [1] })` use `client.ZUNION({ key: 'key', weight: 1 }])`
91+
- `ZUNION_WITHSCORES`: instead of `client.ZUNION_WITHSCORES('key', { WEIGHTS: [1] })` use `client.ZUNION_WITHSCORES({ key: 'key', weight: 1 }])`
8992
- `SETNX`: `boolean` -> `number` [^boolean-to-number]
9093
- `COPY`: `destinationDb` -> `DB`, `replace` -> `REPLACE`, `boolean` -> `number` [^boolean-to-number]
9194
- `EXPIRE`: `boolean` -> `number` [^boolean-to-number]
@@ -104,6 +107,7 @@ Some command arguments/replies have changed to align more closely to data types
104107
- `GEOSEARCH_WITH`/`GEORADIUS_WITH`: `GeoReplyWith` -> `GEO_REPLY_WITH` [^enum-to-constants]
105108
- `GEORADIUSSTORE` -> `GEORADIUS_STORE`
106109
- `GEORADIUSBYMEMBERSTORE` -> `GEORADIUSBYMEMBER_STORE`
110+
- `XACK`: `boolean` -> `number` [^boolean-to-number]
107111

108112
[^enum-to-constants]: TODO
109113

packages/client/lib/commands/BITPOS.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
import BITPOS from './BITPOS';
44

5-
describe.only('BITPOS', () => {
5+
describe('BITPOS', () => {
66
describe('transformArguments', () => {
77
it('simple', () => {
88
assert.deepEqual(
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { RedisFlushModes, transformArguments } from './FLUSHALL';
3+
import FLUSHALL, { REDIS_FLUSH_MODES } from './FLUSHALL';
44

55
describe('FLUSHALL', () => {
6-
describe('transformArguments', () => {
7-
it('default', () => {
8-
assert.deepEqual(
9-
transformArguments(),
10-
['FLUSHALL']
11-
);
12-
});
6+
describe('transformArguments', () => {
7+
it('default', () => {
8+
assert.deepEqual(
9+
FLUSHALL.transformArguments(),
10+
['FLUSHALL']
11+
);
12+
});
1313

14-
it('ASYNC', () => {
15-
assert.deepEqual(
16-
transformArguments(RedisFlushModes.ASYNC),
17-
['FLUSHALL', 'ASYNC']
18-
);
19-
});
14+
it('ASYNC', () => {
15+
assert.deepEqual(
16+
FLUSHALL.transformArguments(REDIS_FLUSH_MODES.ASYNC),
17+
['FLUSHALL', 'ASYNC']
18+
);
19+
});
2020

21-
it('SYNC', () => {
22-
assert.deepEqual(
23-
transformArguments(RedisFlushModes.SYNC),
24-
['FLUSHALL', 'SYNC']
25-
);
26-
});
21+
it('SYNC', () => {
22+
assert.deepEqual(
23+
FLUSHALL.transformArguments(REDIS_FLUSH_MODES.SYNC),
24+
['FLUSHALL', 'SYNC']
25+
);
2726
});
27+
});
2828

29-
testUtils.testWithClient('client.flushAll', async client => {
30-
assert.equal(
31-
await client.flushAll(),
32-
'OK'
33-
);
34-
}, GLOBAL.SERVERS.OPEN);
29+
testUtils.testWithClient('client.flushAll', async client => {
30+
assert.equal(
31+
await client.flushAll(),
32+
'OK'
33+
);
34+
}, GLOBAL.SERVERS.OPEN);
3535
});

packages/client/lib/commands/FLUSHALL.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const REDIS_FLUSH_MODES = {
88
export type RedisFlushModes = typeof REDIS_FLUSH_MODES[keyof typeof REDIS_FLUSH_MODES];
99

1010
export default {
11+
FIRST_KEY_INDEX: undefined,
12+
IS_READ_ONLY: false,
1113
transformArguments(mode?: RedisFlushModes) {
1214
const args = ['FLUSHALL'];
1315

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import { RedisFlushModes } from './FLUSHALL';
4-
import { transformArguments } from './FLUSHDB';
3+
import FLUSHDB from './FLUSHDB';
4+
import { REDIS_FLUSH_MODES } from './FLUSHALL';
55

66
describe('FLUSHDB', () => {
7-
describe('transformArguments', () => {
8-
it('default', () => {
9-
assert.deepEqual(
10-
transformArguments(),
11-
['FLUSHDB']
12-
);
13-
});
7+
describe('transformArguments', () => {
8+
it('default', () => {
9+
assert.deepEqual(
10+
FLUSHDB.transformArguments(),
11+
['FLUSHDB']
12+
);
13+
});
1414

15-
it('ASYNC', () => {
16-
assert.deepEqual(
17-
transformArguments(RedisFlushModes.ASYNC),
18-
['FLUSHDB', 'ASYNC']
19-
);
20-
});
15+
it('ASYNC', () => {
16+
assert.deepEqual(
17+
FLUSHDB.transformArguments(REDIS_FLUSH_MODES.ASYNC),
18+
['FLUSHDB', 'ASYNC']
19+
);
20+
});
2121

22-
it('SYNC', () => {
23-
assert.deepEqual(
24-
transformArguments(RedisFlushModes.SYNC),
25-
['FLUSHDB', 'SYNC']
26-
);
27-
});
22+
it('SYNC', () => {
23+
assert.deepEqual(
24+
FLUSHDB.transformArguments(REDIS_FLUSH_MODES.SYNC),
25+
['FLUSHDB', 'SYNC']
26+
);
2827
});
28+
});
2929

30-
testUtils.testWithClient('client.flushDb', async client => {
31-
assert.equal(
32-
await client.flushDb(),
33-
'OK'
34-
);
35-
}, GLOBAL.SERVERS.OPEN);
30+
testUtils.testWithClient('client.flushDb', async client => {
31+
assert.equal(
32+
await client.flushDb(),
33+
'OK'
34+
);
35+
}, GLOBAL.SERVERS.OPEN);
3636
});

packages/client/lib/commands/FLUSHDB.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { SimpleStringReply, Command } from '../RESP/types';
22
import { RedisFlushModes } from './FLUSHALL';
33

44
export default {
5+
FIRST_KEY_INDEX: undefined,
6+
IS_READ_ONLY: false,
57
transformArguments(mode?: RedisFlushModes) {
68
const args = ['FLUSHDB'];
79

packages/client/lib/commands/GEOSEARCH.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export function pushGeoSearchArguments(
4343
args.push('BYBOX', by.width.toString(), by.height.toString(), by.unit);
4444
}
4545

46-
if (options?.SORT) {
47-
args.push(options.SORT);
48-
}
49-
5046
pushGeoSearchOptions(args, options);
5147

5248
return args;

packages/client/lib/commands/HEXISTS.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('HEXISTS', () => {
1313
testUtils.testAll('hExists', async client => {
1414
assert.equal(
1515
await client.hExists('key', 'field'),
16-
false
16+
0
1717
);
1818
}, {
1919
client: GLOBAL.SERVERS.OPEN,

packages/client/lib/commands/MOVE.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('MOVE', () => {
1313
testUtils.testAll('move', async client => {
1414
assert.equal(
1515
await client.move('key', 1),
16-
1
16+
0
1717
);
1818
}, {
1919
client: GLOBAL.SERVERS.OPEN,

packages/client/lib/commands/XADD.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RedisArgument, BlobStringReply, Command } from '../RESP/types';
1+
import { RedisArgument, BlobStringReply, Command, CommandArguments } from '../RESP/types';
22

33
export interface XAddOptions {
44
TRIM?: {
@@ -9,6 +9,37 @@ export interface XAddOptions {
99
};
1010
}
1111

12+
export function pushXAddArguments(
13+
args: CommandArguments,
14+
id: RedisArgument,
15+
message: Record<string, RedisArgument>,
16+
options?: XAddOptions
17+
) {
18+
if (options?.TRIM) {
19+
if (options.TRIM.strategy) {
20+
args.push(options.TRIM.strategy);
21+
}
22+
23+
if (options.TRIM.strategyModifier) {
24+
args.push(options.TRIM.strategyModifier);
25+
}
26+
27+
args.push(options.TRIM.threshold.toString());
28+
29+
if (options.TRIM.limit) {
30+
args.push('LIMIT', options.TRIM.limit.toString());
31+
}
32+
}
33+
34+
args.push(id);
35+
36+
for (const [key, value] of Object.entries(message)) {
37+
args.push(key, value);
38+
}
39+
40+
return args;
41+
}
42+
1243
export default {
1344
FIRST_KEY_INDEX: 1,
1445
IS_READ_ONLY: false,
@@ -18,31 +49,7 @@ export default {
1849
message: Record<string, RedisArgument>,
1950
options?: XAddOptions
2051
) {
21-
const args = ['XADD', key];
22-
23-
if (options?.TRIM) {
24-
if (options.TRIM.strategy) {
25-
args.push(options.TRIM.strategy);
26-
}
27-
28-
if (options.TRIM.strategyModifier) {
29-
args.push(options.TRIM.strategyModifier);
30-
}
31-
32-
args.push(options.TRIM.threshold.toString());
33-
34-
if (options.TRIM.limit) {
35-
args.push('LIMIT', options.TRIM.limit.toString());
36-
}
37-
}
38-
39-
args.push(id);
40-
41-
for (const [key, value] of Object.entries(message)) {
42-
args.push(key, value);
43-
}
44-
45-
return args;
52+
return pushXAddArguments(['XADD', key], id, message, options);
4653
},
4754
transformReply: undefined as unknown as () => BlobStringReply
4855
} as const satisfies Command;

0 commit comments

Comments
 (0)