菜单
开源

Client.hget(key, field)

返回存储在键为 key 的哈希中与 field 关联的值。

参数

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

返回值

类型成功解析时返回拒绝时
Promise<string>成功时,Promise 解析为与 field 关联的值。如果哈希不存在,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.hget('myhash', 'myfield');
  await redisClient.hdel('myhash', 'myfield');
}