菜单
开源

Client.hkeys(key)

返回存储在 key 的散列中的所有字段。

参数

参数类型描述
keystring持有要获取字段的散列的 key。

返回

类型解决为当...时拒绝
Promise<string[]>成功时,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', 'myvalue');
  await redisClient.hset('myhash', 'myotherfield', 'myothervalue');

  const keys = await redisClient.hkeys('myhash');
  if (keys.length !== 2) {
    throw new Error('myhash should have 2 keys');
  }

  console.log(`myhash has keys ${keys}`);
}