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 | 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x 6x 2x 2x 2x 6x 2x 2x | import { Logger } from "../../../logger";
import { IRequest } from "../../../server/request";
import { DataType } from "../../data/data-type";
import { Database } from "../../data/database";
import { DatabaseValue } from "../../data/database-value";
import { RedisToken } from "../../protocol/redis-token";
import { IRespCommand } from "../resp-command";
/**
* ### Available since 1.0.0.
* ### LPUSH key element [element ...]
* Insert all the specified values at the head of the list stored at key. If key does not
* exist, it is created as empty list before performing the push operations. When key holds
* a value that is not a list, an error is returned.
*
* It is possible to push multiple elements using a single command call just specifying
* multiple arguments at the end of the command. Elements are inserted one after the other
* to the head of the list, from the leftmost element to the rightmost element. So for instance
* the command LPUSH mylist a b c will result into a list containing c as first element, b as
* second element and a as third element.
*
* ### Return value
* Integer reply: the length of the list after the push operations.
*/
export class LPushCommand extends IRespCommand {
public DbDataType = DataType.LIST
public maxParams = -1
public minParams = 2
public name = "lpush"
private logger: Logger = new Logger(module.id);
public execSync(request: IRequest, db: Database): RedisToken {
this.logger.debug(
`${request.getCommand()}.execute(%s)`,
...request.getParams()
);
const key: string = request.getParam(0);
let list: DatabaseValue = db.get(key);
this.logger.debug(`Getting list "${key}"`);
Eif (!list) {
this.logger.debug(`Creating new list: "${key}"`);
list = new DatabaseValue(
DataType.LIST,
[]
);
}
for (let index = 1; index < request.getParams().length; index++) {
const element = request.getParam(index);
this.logger.debug(`PUSHING element "${element}" to list "${key}"`);
list.getList().unshift(element);
}
const size: number = list.getList().length;
// To remain consistent with redis 2.6+, we raise events only after all pushes have completed
db.put(
key,
list
);
for (let index = 1; index < request.getParams().length; index++) {
request.getServerContext().emit(`__keyevent@${request.getSession().getCurrentDb()}__:lpush ${key}`);
}
this.logger.debug(`Returning list ${key} size ${size}`);
return RedisToken.integer(size);
}
}
|