tencent cloud

Client.lRem
Last updated: 2025-03-11 20:05:02
Client.lRem
Last updated: 2025-03-11 20:05:02
The lRem method is used to remove elements from the list.
lRem(key: string, count: number, value: string | number): number

Parameters

Parameter
Type
Description
key
string
Key name.
count
number
The number of elements removed. Positive values indicate starting from the head of the list, negative values indicate starting from the tail of the list, and 0 indicates removing all.
value
string | number
The value of the removed element.

Return

Type
Description
number
On success, the number of removed elements is returned.

Samples

import redis from "pts/redis";

let client = new redis.Client("redis://:<password>@<host>:6379/0");

export default function main() {
let lPushResp = client.lPush("list", "foo", "bar", "zoo", "foo", "bar", "zoo");
console.log(redis lPush ${lPushResp}); // 6
let lRemResp1 = client.lRem("list", 1, "bar");
console.log(redis lRem ${lRemResp1}); // 1
let lRemResp2 = client.lRem("list", -1, "foo");
console.log(redis lRem ${lRemResp2}); // 1
let lRangeResp = client.lRange("list", 0, 4);
console.log(redis lRange ${lRangeResp}); // zoo,foo,zoo,bar
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback