All files redisApi.js

95.65% Statements 22/23
75% Branches 3/4
100% Functions 10/10
94.74% Lines 18/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3725x   1x 35x 35x   1x       1x 37x 37x       37x     37x     37x     1x   1x 1x   7x   3x   1x 25x  
const serializeData = data => JSON.stringify(data);
 
const safeParse = (str) => {
    try {
        return JSON.parse(str);
    } catch (e) {
        return str;
    }
};
 
const invokeCommand = (client, command, name, ...args) =>
    new Promise((resolve, reject) => {
        const params = [
            name,
            ...args,
            (err, data) => {
                Iif (err) {
                    return reject(err);
                }
                return resolve(Array.isArray(data) ? data.map(safeParse) : safeParse(data));
            }
        ];
        client[command](...params);
    });
 
export const del = async (client, ...keys) => await invokeCommand(client, 'DEL', ...keys);
 
export const hdel = async (client, key, ...fields) =>
    await invokeCommand(client, 'HDEL', key, ...fields);
 
export const hget = async (client, key, field) => await invokeCommand(client, 'HGET', key, field);
 
export const hkeys = async (client, key) => await invokeCommand(client, 'HKEYS', key);
 
export const hset = async (client, key, field, value) =>
    await invokeCommand(client, 'HSET', key, field, serializeData(value));