All files / lib/commands SET.ts

100% Statements 24/24
100% Branches 20/20
100% Functions 2/2
100% Lines 24/24

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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 781x                                                                               1x 113x   113x 103x     10x 2x 8x 1x 7x 1x 6x 1x     10x 2x 8x 1x     10x 1x     10x 3x     10x     1x 103x    
export const FIRST_KEY_INDEX = 1;
 
interface EX {
    EX: number;
}
 
interface PX {
    PX: number
}
 
interface EXAT {
    EXAT: number;
}
 
interface PXAT {
    PXAT: number;
}
 
interface KEEPTTL {
    KEEPTTL: true;
}
 
type SetTTL = EX | PX | EXAT | PXAT | KEEPTTL | {};
 
interface NX {
    NX: true;
}
 
interface XX {
    XX: true;
}
 
type SetGuards = NX | XX | {};
 
interface SetCommonOptions {
    GET: true
}
 
type SetOptions = SetTTL & SetGuards & (SetCommonOptions | {});
 
export function transformArguments(key: string, value: string, options?: SetOptions): Array<string> {
    const args = ['SET', key, value];
 
    if (!options) {
        return args;
    }
 
    if ('EX' in options) {
        args.push('EX', options.EX.toString());
    } else if ('PX' in options) {
        args.push('PX', options.PX.toString());
    } else if ('EXAT' in options) {
        args.push('EXAT', options.EXAT.toString());
    } else if ('PXAT' in options) {
        args.push('PXAT', options.PXAT.toString());
    }
 
    if ((<NX>options).NX) {
        args.push('NX');
    } else if ((<XX>options).XX) {
        args.push('XX');
    }
 
    if ((<KEEPTTL>options).KEEPTTL) {
        args.push('KEEPTTL');
    }
 
    if ((<SetCommonOptions>options).GET) {
        args.push('GET');
    }
 
    return args;
}
 
export function transformReply(reply?: string): string | null {
    return reply ?? null;
}