All files / lib/commands SCAN.ts

100% Statements 12/12
100% Branches 6/6
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 37 381x               1x 16x   16x 2x     16x 2x     16x 2x     16x               1x 13x          
export const IS_READ_ONLY = true;
 
export interface ScanOptions {
    MATCH?: string;
    COUNT?: number;
    TYPE?: string;
}
 
export function transformArguments(cursor: number, options?: ScanOptions): Array<string> {
    const args = ['SCAN', cursor.toString()];
 
    if (options?.MATCH) {
        args.push('MATCH', options.MATCH);
    }
 
    if (options?.COUNT) {
        args.push('COUNT', options.COUNT.toString());
    }
 
    if (options?.TYPE) {
        args.push('TYPE', options.TYPE);
    }
    
    return args;
}
 
interface ScanReply {
    cursor: number;
    keys: Array<string>
}
 
export function transformReply(reply: [string, Array<string>]): ScanReply {
    return {
        cursor: Number(reply[0]),
        keys: reply[1]
    };
}