1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00
This commit is contained in:
leibale
2021-12-30 13:17:44 -05:00
parent 5c0aad0780
commit c581d5de3a
3 changed files with 38 additions and 18 deletions

View File

@@ -26,12 +26,32 @@ describe('ARRPOP', () => {
}); });
}); });
testUtils.testWithClient('client.json.arrPop', async client => { describe('client.json.arrPop', () => {
await client.json.set('key', '$', []); testUtils.testWithClient('null', async client => {
await client.json.set('key', '.', []);
assert.equal(
await client.json.arrPop('key', '.'),
null
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('with value', async client => {
await client.json.set('key', '.', ['value']);
assert.equal(
await client.json.arrPop('key', '.'),
'value'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('array', async client => {
await client.json.set('key', '$', ['value']);
assert.deepEqual( assert.deepEqual(
await client.json.arrPop('key', '$'), await client.json.arrPop('key', '$'),
[null] ['value']
); );
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
}); });
});

View File

@@ -1,3 +1,5 @@
import { RedisJSON, transformRedisJsonNullReply } from '.';
export const FIRST_KEY_INDEX = 1; export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, path?: string, index?: number): Array<string> { export function transformArguments(key: string, path?: string, index?: number): Array<string> {
@@ -14,4 +16,12 @@ export function transformArguments(key: string, path?: string, index?: number):
return args; return args;
} }
export { transformRedisJsonNullArrayNullReply as transformReply } from '.'; export function transformReply(reply: null | string | Array<null | string>): null | RedisJSON | Array<RedisJSON> {
if (reply === null) return null;
if (Array.isArray(reply)) {
return reply.map(transformRedisJsonNullReply);
}
return transformRedisJsonNullReply(reply);
}

View File

@@ -79,22 +79,12 @@ export function transformRedisJsonReply(json: string): RedisJSON {
return JSON.parse(json); return JSON.parse(json);
} }
export function transformRedisJsonArrayReply(jsons: Array<string>): Array<RedisJSON> {
return jsons.map(transformRedisJsonReply)
}
export function transformRedisJsonNullReply(json: string | null): RedisJSON | null { export function transformRedisJsonNullReply(json: string | null): RedisJSON | null {
if (json === null) return null; if (json === null) return null;
return transformRedisJsonReply(json); return transformRedisJsonReply(json);
} }
export function transformRedisJsonNullArrayNullReply(jsons: Array<string | null> | null): Array<RedisJSON | null> | null {
if (jsons === null) return null;
return jsons.map(transformRedisJsonNullReply);
}
export function transformNumbersReply(reply: string): number | Array<number> { export function transformNumbersReply(reply: string): number | Array<number> {
return JSON.parse(reply); return JSON.parse(reply);
} }