Client.llen(key)
返回存储在 key
的列表的长度。如果 key
不存在,则将其视为空列表,并返回 0。
参数
参数 | 类型 | 描述 |
---|---|---|
key | string | 要获取长度的列表所在的 key。 |
返回值
类型 | 成功时解析为 | 失败时拒绝 |
---|---|---|
Promise<number> | 成功时,Promise 解析为 key 处列表的长度。 | 如果列表不存在,Promise 将因错误而被拒绝。 |
示例
import redis from 'k6/experimental/redis';
// Instantiate a new redis client
const redisClient = new redis.Client('redis://:6379');
export default function () {
redisClient
.rpush('mylist', 'first')
.then((_) => redisClient.rpush('mylist', 'second'))
.then((_) => redisClient.rpush('mylist', 'third'))
.then((_) => redisClient.llen('mylist'))
.then((length) => {
if (length !== 3) {
throw new Error('llen operations should have returned 3');
}
});
}