All files / src/resp/command multi-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  1x 1x   1x                     1x 4x   4x   4x   4x     6x       6x 5x 5x     1x      
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 1.2.0.
 * ### MULTI
 *
 * Marks the start of a transaction block. Subsequent commands will be queued for atomic
 * execution using {@link resp/command/exec-command.ExecCommand | EXEC}.
 * ### Return value
 * Simple string reply: always OK.
 */
export class MultiCommand extends IRespCommand {
    public minParams = 0
 
    public maxParams = 0
 
    public name = "multi"
 
    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()) {
            request.getSession().startTransaction();
            return RedisToken.responseOk();
        }
 
        return RedisToken.error("ERR MULTI calls can not be nested");
    }
}