# hmget & hmset

### 1. 基本語法

{% hint style="warning" %}
[官方文件](https://redis.io/commands/hset)表示：Redis 4.0.0開始, [hset](https://aiii-mike.gitbook.io/redis/command/hash/hset-hget-hdel)語法已支援設置多組鍵值對資料
{% endhint %}

#### **(1) hmset(`hkey` ,`subkey, value[, subkey, value, ...]`**, **`callback`)**&#x20;

&#x70BA;**`hkey`**&#x4E00;次設置多&#x7D44;**`subkey`**&#x8207;**`value`**&#x7684;鍵值對資料。

#### **(2) hmget(`hkey` , `subkey[, subkey, ...]`,`callback`)**&#x20;

回&#x50B3;**`hkey`**&#x5E95;下多&#x7D44;**`subkey`**&#x5C0D;應的資料內容。

{% tabs %}
{% tab title="TypeScript" %}

```typescript
const dict = { 
    name: 'Brooks Hatlen', 
    gender: 'M', 
    age: '73' 
};

client.hmset('user:2', dict);
client.hmget('user:2', 'name', 'age', (err, vals) => {
    console.log(vals);
});
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output-TS" %}

```
[ 'Brooks Hatlen', '73' ]
```

{% endtab %}
{% endtabs %}
