菜单
开源

Client.hgetall(key)

返回存储在 key 处的哈希的所有字段和值。

参数

参数类型描述
keystring包含要获取字段的哈希的 key。

返回值

类型解析为当...时被拒绝
Promise<[key: string]string>成功时,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 object = await redisClient.hgetall('myhash');
  console.log(`myhash has key:value pairs ${JSON.stringify(object)}`);
}