菜单
开源

Client.hvals(key)

返回存储在 key 上的哈希的所有值。

参数

参数类型描述
keystring持有要获取字段的哈希的键。

返回值

类型成功时返回失败时返回
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 values = await redisClient.hvals('myhash');
  if (values.length !== 2) {
    throw new Error('myhash should have 2 values');
  }

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