All files / src/resp/command discard-command.ts

100% Statements 13/13
100% Branches 2/2
100% Functions 2/2
100% Lines 13/13

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  1x 1x   1x                       1x 4x   4x   4x   4x     3x       3x 1x     2x 2x      
import { Database } from "../data/database";
import { Logger } from "../../logger";
import { RedisToken } from "../protocol/redis-token";
import { IRequest } from "../../server/request";
import { IRespCommand } from "./resp-command";
 
/**
 * ### Available since 2.0.0.
 * ### DISCARD
 * Flushes all previously queued commands in a transaction and restores the connection state
 * to normal.
 *
 * If [WATCH]{public link WatchCommand} was used, DISCARD unwatches all keys watched by the connection.
 * ### Return value
 * Simple string reply: always OK.
 */
export class DiscardCommand extends IRespCommand {
    public minParams = 0
 
    public maxParams = 0
 
    public name = "discard"
 
    private logger: Logger = new Logger(module.id);
 
    public execSync(request: IRequest, db: Database): RedisToken {
        this.logger.debug(
            `${request.getCommand()}.execute(%s)`,
            ...request.getParams()
        );
        if (!request.getSession().inTransaction()) {
            return RedisToken.error("ERR DISCARD without MULTI");
        }
 
        request.getSession().abortTransaction();
        return RedisToken.responseOk();
    }
}