Client.lrem(key, count, value)
从存储在 key
的列表中移除 count
个首次出现的 value
。如果 count
为正数,则从列表开头移除元素。如果 count
为负数,则从列表末尾移除元素。如果 count
为零,则移除所有匹配 value
的元素。
参数
参数 | 类型 | 描述 |
---|---|---|
key | string | 存储要移除元素的列表的 key。 |
count | number | 要移除的元素数量。 |
value | string | 要从列表中移除的值。 |
返回值
类型 | 成功时解析为 | 失败时拒绝 |
---|---|---|
Promise<number> | 成功时,Promise 解析为移除的元素数量。 | 如果列表不存在,Promise 将因错误而被拒绝。 |
示例
import redis from 'k6/experimental/redis';
// Instantiate a new redis client
const redisClient = new redis.Client('redis://:6379');
export default async function () {
await redisClient.rpush('mylist', 'first');
await redisClient.rpush('mylist', 'second');
await redisClient.rpush('mylist', 'first');
await redisClient.rpush('mylist', 'second');
await redisClient.lrem('mylist', 0, 'second');
const length = await redisClient.lrem('mylist', 1, 'first');
if (length !== 1) {
throw new Error('lrem operations should have left 1 item behind');
}
await redisClient.lpop('mylist');
}