Client.hset(key, field, value)
设置存储在 key
中的哈希的指定 field
为 value
。如果 key
不存在,则创建一个新的哈希类型的 key。如果 field
在哈希中已存在,则会覆盖。
参数
参数 | 类型 | 描述 |
---|---|---|
key | 字符串 | 包含要设置字段的哈希的 key。 |
field | 字符串 | 要在哈希中设置的 field。 |
value | 字符串 | 要将 field 设置为的 value。 |
返回值
类型 | 成功时返回 | 失败时返回 |
---|---|---|
Promise<number> | 成功时,Promise 返回已添加字段的数量。 | 如果哈希不存在,Promise 会因错误而被拒绝。 |
示例
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');
}