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

# MONITOR

> Stream all commands received.

Use `MONITOR` to stream every command the server processes, as it happens, to the current connection.

The connection turns into a continuous feed and stops accepting other commands, so it must be a dedicated one; closing it is how you stop monitoring. Each line carries a timestamp, the client that sent the command, and the command with its arguments.

It is a debugging tool: it shows the traffic of all clients, arguments included, so it can expose sensitive data, and the added work costs the server throughput while it is running. Use it briefly and against non-production data where possible.

## Syntax

```redis theme={"system"}
MONITOR
```

## Arguments

This command takes no arguments.

## Important points

* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint.
* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths.
* MONITOR changes the TCP connection into a continuous command stream. Use a dedicated connection and close it to stop monitoring.

## 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    | Simple string `OK`, then a stream of bulk strings, one per command the server executes |
| RESP3    | Simple string `OK`, then a stream of bulk strings, one per command the server executes |

<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"}
    MONITOR
    ```
  </Accordion>

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

    const redis = new Redis(process.env.REDIS_URL!);
    redis.monitor((error, monitor) => {
      if (error) throw error;
      monitor.on("monitor", (time, args, source, database) => {
        console.log({ time, args, source, database });
      });
    });
    ```
  </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();

    await client.monitor((command) => {
      console.log(command);
    });
    ```
  </Accordion>

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

    client = redis.from_url(os.environ["REDIS_URL"])
    with client.monitor() as monitor:
        for command in monitor.listen():
            print(command)
    ```
  </Accordion>

  <Accordion title="jedis" icon="java" iconType="brands">
    ```java theme={"system"}
    import java.net.URI;
    import redis.clients.jedis.Jedis;
    import redis.clients.jedis.JedisMonitor;

    try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
      jedis.monitor(new JedisMonitor() {
        @Override
        public void onCommand(String command) {
          System.out.println(command);
        }
      });
    }
    ```
  </Accordion>

  <Accordion title="redis-rs" icon="rust" iconType="brands">
    ```rust theme={"system"}
    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 packed = redis::cmd("MONITOR").get_packed_command();
        connection.send_packed_command(&packed)?;
        loop {
            println!("{:?}", connection.recv_response()?);
        }
    }
    ```
  </Accordion>
</AccordionGroup>


## Related topics

- [Flow Control](/docs/qstash/features/flowcontrol.md)
- [Monitor & Manage](/docs/workflow/features/flow-control/monitor.md)
- [Uptime Monitor](/docs/common/help/uptime.md)
- [Monitor your usage](/docs/redis/howto/monitoryourusage.md)
