Client.hlen(key)
返回存储在 key
上的哈希中字段的数量。
参数
参数 | 类型 | 描述 |
---|---|---|
key | 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.hset('myhash', 'myfield', 10);
await redisClient.hset('myhash', 'myotherfield', 20);
await redisClient.hlen('myhash');
}