菜单
开源

Client.hlen(key)

返回存储在 key 上的哈希中字段的数量。

参数

参数类型描述
keystring存储哈希的键,用于获取字段。

返回值

类型成功时失败时
Promise<number>成功时,Promise 返回哈希中的字段数量。如果哈希不存在,Promise 将返回一个错误。

示例

JavaScript
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');
}