> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HGET

> Get the value of a hash field.

Use `HGET` to read the value of a single field of a hash.

The reply is null when either the field or the whole key is missing, so the two cases cannot be told apart from the reply alone; use [`HEXISTS`](/docs/redis/commands/hash/hexists) when that difference matters. To read several fields use [`HMGET`](/docs/redis/commands/hash/hmget) rather than repeated calls, and to read all of them use [`HGETALL`](/docs/redis/commands/hash/hgetall).

## Syntax

```redis theme={"system"}
HGET <key> <field>
```

## Arguments

| Argument | Required | Repeatable | Description |
| - | - | - | - |
| `<key>` | Yes | No | Redis key targeted by the command. |
| `<field>` | Yes | No | Hash field name. |

## Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

| Protocol | Reply |
| - | - |
| RESP2 | Bulk string or Null bulk string or null array |
| RESP3 | Bulk string or Null |

> [!NOTE]
>
> Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

## Examples

TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.

> **Redis CLI**
>
> ```bash theme={"system"}
> HGET my-key field
> ```

> **@upstash/redis**
>
> ```ts theme={"system"}
> import { Redis } from "@upstash/redis";
>
> const redis = Redis.fromEnv();
>
> await redis.hset("key", {field: "value"});
> const field = await redis.hget("key", "field");
> console.log(field); // "value"
> ```

> **upstash\_redis**
>
> ```python theme={"system"}
> from upstash_redis import Redis
>
> redis = Redis.from_env()
> result = redis.hget("my-key", "field")
> print(result)
> ```

> **ioredis**
>
> ```ts theme={"system"}
> import Redis from "ioredis";
>
> const redis = new Redis(process.env.REDIS_URL!);
> const result = await redis.hget("my-key", "field");
> console.log(result);
> ```

> **node-redis**
>
> ```ts theme={"system"}
> import { createClient } from "redis";
>
> const client = await createClient({ url: process.env.REDIS_URL })
>   .on("error", console.error)
>   .connect();
> const result = await client.hGet("my-key", "field");
> console.log(result);
> ```

> **redis-py**
>
> ```python theme={"system"}
> import os
> import redis
>
> client = redis.from_url(os.environ["REDIS_URL"])
> result = client.hget("my-key", "field")
> print(result)
> ```

> **go-redis**
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "fmt"
>     "os"
>
>     "github.com/redis/go-redis/v9"
> )
>
> func main() {
>     opts, err := redis.ParseURL(os.Getenv("REDIS_URL"))
>     if err != nil {
>         panic(err)
>     }
>     client := redis.NewClient(opts)
>     result, err := client.HGet(context.Background(), "my-key", "field").Result()
>     if err != nil {
>         panic(err)
>     }
>     fmt.Println(result)
> }
> ```

> **jedis**
>
> ```java theme={"system"}
> import java.net.URI;
>
> import redis.clients.jedis.Jedis;
>
> try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
>   Object result = jedis.hget("my-key", "field");
>   System.out.println(result);
> }
> ```

> **redis-rs**
>
> ```rust theme={"system"}
> use redis::TypedCommands;
>
> fn main() -> redis::RedisResult<()> {
>     let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set");
>     let client = redis::Client::open(url)?;
>     let mut connection = client.get_connection()?;
>
>     let result = connection.hget("my-key", "field")?;
>     println!("{result:?}");
>     Ok(())
> }
> ```


## Related topics

- [HGET](/docs/redis/sdks/ts/commands/hash/hget.md)
- [HGETALL](/docs/redis/commands/hash/hgetall.md)
- [HGETDEL](/docs/redis/commands/hash/hgetdel.md)
- [HGETEX](/docs/redis/commands/hash/hgetex.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.