> ## 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.

# XREAD

> Read stream entries.

Use `XREAD` to read entries from one or more streams that are newer than a given ID.

After `STREAMS`, all keys are listed first and then exactly one ID for each key, in the same order. Only entries with an ID greater than the one you give are returned, and the special ID `$` means "only entries added after this call", which is how a client starts tailing a live stream.

`BLOCK <milliseconds>` waits for new data instead of returning an empty reply, with `0` waiting indefinitely, which turns the command into an efficient follow rather than a polling loop. `COUNT` caps how many entries per stream come back.

`XREAD` keeps no server-side position: the client remembers the last ID it processed and passes it on the next call, and every reader sees every entry. When work should be split across consumers, with the server tracking what has been delivered and acknowledged, use a consumer group and [`XREADGROUP`](/docs/redis/commands/streams/xreadgroup).

## Syntax

```redis theme={"system"}
XREAD
  [COUNT <count>]
  [BLOCK <milliseconds>]
  STREAMS <key> [<key> ...] <ID> [<ID> ...]
```

## Arguments

| Argument                                    | Required | Repeatable | Description                                                                   |
| ------------------------------------------- | -------- | ---------- | ----------------------------------------------------------------------------- |
| `COUNT <count>`                             | No       | No         | Maximum number of entries to return per stream.                               |
| `BLOCK <milliseconds>`                      | No       | No         | Milliseconds to block waiting for new entries; `0` blocks indefinitely.       |
| `STREAMS <key> [<key> ...] <ID> [<ID> ...]` | Yes      | No         | Streams to read. List every key first, then one ID per key in the same order. |

## Important points

* A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout.
* After `STREAMS`, provide all keys first and then exactly one ID for each key, in the same order.

## 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    | Flat array of alternating keys and values or Null bulk string or null array |
| RESP3    | Map 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.
</Note>

## Examples

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

<AccordionGroup>
  <Accordion title="Redis CLI" icon="terminal">
    ```bash theme={"system"}
    XREAD STREAMS my-key 0-0
    ```
  </Accordion>

  <Accordion title="@upstash/redis" icon="node-js" iconType="brands">
    ```ts theme={"system"}
    import { Redis } from "@upstash/redis";

    const redis = Redis.fromEnv();

    const result = await redis.xread("mystream", "0-0");
    ```
  </Accordion>

  <Accordion title="upstash_redis" icon="python" iconType="brands">
    ```python theme={"system"}
    from upstash_redis import Redis

    redis = Redis.from_env()
    result = redis.xread({"my-key": "0-0"})
    print(result)
    ```
  </Accordion>

  <Accordion title="ioredis" icon="node-js" iconType="brands">
    ```ts theme={"system"}
    import Redis from "ioredis";

    const redis = new Redis(process.env.REDIS_URL!);
    const result = await redis.xread("STREAMS", "my-key", "0-0");
    console.log(result);
    ```
  </Accordion>

  <Accordion title="node-redis" icon="node-js" iconType="brands">
    ```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.xRead({ key: "my-key", id: "0-0" });
    console.log(result);
    ```
  </Accordion>

  <Accordion title="redis-py" icon="python" iconType="brands">
    ```python theme={"system"}
    import os
    import redis

    client = redis.from_url(os.environ["REDIS_URL"])
    result = client.xread({"my-key": "0-0"})
    print(result)
    ```
  </Accordion>

  <Accordion title="go-redis" icon="golang" iconType="brands">
    ```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.XRead(context.Background(), &redis.XReadArgs{Streams: []string{"my-key", "0-0"}}).Result()
        if err != nil {
            panic(err)
        }
        fmt.Println(result)
    }
    ```
  </Accordion>

  <Accordion title="jedis" icon="java" iconType="brands">
    ```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.xread(redis.clients.jedis.params.XReadParams.xReadParams(), java.util.Map.of("my-key", new redis.clients.jedis.StreamEntryID("0-0")));
      System.out.println(result);
    }
    ```
  </Accordion>

  <Accordion title="redis-rs" icon="rust" iconType="brands">
    ```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.xread(&["my-key"], &["0-0"])?;
        println!("{result:?}");
        Ok(())
    }
    ```
  </Accordion>
</AccordionGroup>


## Related topics

- [XREAD](/docs/redis/sdks/ts/commands/stream/xread.md)
- [XREADGROUP](/docs/redis/commands/streams/xreadgroup.md)
