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 78 79 | 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x | 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. * ### RPOP key * * Removes and returns the last element of the list stored at key. * ### Return value * Bulk string reply: the value of the last element, or nil when key does not exist. * ### Examples * ``` * redis> RPUSH mylist "one" * (integer) 1 * redis> RPUSH mylist "two" * (integer) 2 * redis> RPUSH mylist "three" * (integer) 3 * redis> RPOP mylist * "three" * redis> LRANGE mylist 0 -1 * 1) "one" * 2) "two" * redis> * ``` */ export class RPopCommand extends IRespCommand { public DbDataType = DataType.LIST public maxParams = 1 public minParams = 1 public name = "rpop" protected logger: Logger = new Logger(module.id); public execSync(request: IRequest, db: Database): RedisToken | Promise<RedisToken> { this.logger.debug( `${request.getCommand()}.execute(%s)`, ...request.getParams() ); return this.process( request, db, request.getParam(0) ); } protected process(request: IRequest, db: Database, key: string): RedisToken { const list: DatabaseValue = db.get(key); this.logger.debug(`Getting list "${key}"`); if (!list) { this.logger.debug(`LIST ${key} does not exist. Returning NIL`); return RedisToken.nullString(); } const result: any = list.getList().pop(); if (list.getList().length > 0) { db.put( key, list ); request.getServerContext().emit(`__keyevent@${request.getSession().getCurrentDb()}__:rpop ${key}`); } else { db.remove(key); request.getServerContext().emit(`__keyevent@${request.getSession().getCurrentDb()}__:rpop ${key}`); request.getServerContext().emit(`__keyevent@${request.getSession().getCurrentDb()}__:del ${key}`); } this.logger.debug(`Returning element ${result}`); return RedisToken.string(result); } } |