Skip to content

Commit c581d5d

Browse files
committed
fix #1802
1 parent 5c0aad0 commit c581d5d

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

packages/json/lib/commands/ARRPOP.spec.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,32 @@ describe('ARRPOP', () => {
2626
});
2727
});
2828

29-
testUtils.testWithClient('client.json.arrPop', async client => {
30-
await client.json.set('key', '$', []);
31-
32-
assert.deepEqual(
33-
await client.json.arrPop('key', '$'),
34-
[null]
35-
);
36-
}, GLOBAL.SERVERS.OPEN);
29+
describe('client.json.arrPop', () => {
30+
testUtils.testWithClient('null', async client => {
31+
await client.json.set('key', '.', []);
32+
33+
assert.equal(
34+
await client.json.arrPop('key', '.'),
35+
null
36+
);
37+
}, GLOBAL.SERVERS.OPEN);
38+
39+
testUtils.testWithClient('with value', async client => {
40+
await client.json.set('key', '.', ['value']);
41+
42+
assert.equal(
43+
await client.json.arrPop('key', '.'),
44+
'value'
45+
);
46+
}, GLOBAL.SERVERS.OPEN);
47+
48+
testUtils.testWithClient('array', async client => {
49+
await client.json.set('key', '$', ['value']);
50+
51+
assert.deepEqual(
52+
await client.json.arrPop('key', '$'),
53+
['value']
54+
);
55+
}, GLOBAL.SERVERS.OPEN);
56+
});
3757
});

packages/json/lib/commands/ARRPOP.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { RedisJSON, transformRedisJsonNullReply } from '.';
2+
13
export const FIRST_KEY_INDEX = 1;
24

35
export function transformArguments(key: string, path?: string, index?: number): Array<string> {
@@ -14,4 +16,12 @@ export function transformArguments(key: string, path?: string, index?: number):
1416
return args;
1517
}
1618

17-
export { transformRedisJsonNullArrayNullReply as transformReply } from '.';
19+
export function transformReply(reply: null | string | Array<null | string>): null | RedisJSON | Array<RedisJSON> {
20+
if (reply === null) return null;
21+
22+
if (Array.isArray(reply)) {
23+
return reply.map(transformRedisJsonNullReply);
24+
}
25+
26+
return transformRedisJsonNullReply(reply);
27+
}

packages/json/lib/commands/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,12 @@ export function transformRedisJsonReply(json: string): RedisJSON {
7979
return JSON.parse(json);
8080
}
8181

82-
export function transformRedisJsonArrayReply(jsons: Array<string>): Array<RedisJSON> {
83-
return jsons.map(transformRedisJsonReply)
84-
}
85-
8682
export function transformRedisJsonNullReply(json: string | null): RedisJSON | null {
8783
if (json === null) return null;
8884

8985
return transformRedisJsonReply(json);
9086
}
9187

92-
export function transformRedisJsonNullArrayNullReply(jsons: Array<string | null> | null): Array<RedisJSON | null> | null {
93-
if (jsons === null) return null;
94-
95-
return jsons.map(transformRedisJsonNullReply);
96-
}
97-
9888
export function transformNumbersReply(reply: string): number | Array<number> {
9989
return JSON.parse(reply);
10090
}

0 commit comments

Comments
 (0)