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

# CLI

> Execute Redis commands interactively with a terminal-like interface

The Redis CLI provides an interactive command-line interface for executing Redis commands directly. Use it for debugging, administration, testing, and running ad-hoc queries against your Redis servers.

## Key Concepts

<CardGroup cols={2}>
  <Card title="Command" icon="code">
    Redis commands consist of a command name followed by arguments (e.g., `GET mykey`).
  </Card>

  <Card title="Response Types" icon="reply">
    Commands return different types: strings, integers, lists, nil, or errors.
  </Card>

  <Card title="Database" icon="database">
    Commands execute against the selected database (0-15). Use SELECT to switch.
  </Card>

  <Card title="History" icon="clock-rotate-left">
    Previous commands are saved in session history for quick recall.
  </Card>
</CardGroup>

## Required Permissions

| Action           | Permission                               |
| ---------------- | ---------------------------------------- |
| Execute commands | `iam:project:infrastructure:redis:write` |

<Warning>
  CLI access requires write permission because commands can modify data. Read-only users cannot access the CLI.
</Warning>

## How to Execute a Command

<Steps>
  <Step title="Select Connection">
    Choose a Redis connection from the dropdown.
  </Step>

  <Step title="Select Database">
    Choose the target database (0-15).
  </Step>

  <Step title="Enter Command">
    Type a Redis command in the input field.
  </Step>

  <Step title="Execute">
    Press Enter or click the Execute button.
  </Step>

  <Step title="View Result">
    The result appears below with execution time and type indicator.
  </Step>
</Steps>

## Keyboard Shortcuts

| Key              | Action                        |
| ---------------- | ----------------------------- |
| `Enter`          | Execute the current command   |
| `↑` (Arrow Up)   | Previous command from history |
| `↓` (Arrow Down) | Next command in history       |

## Quick Commands

Pre-configured commands for common operations:

| Command          | Description                        |
| ---------------- | ---------------------------------- |
| `PING`           | Test connection (returns PONG)     |
| `INFO`           | Server information and statistics  |
| `DBSIZE`         | Number of keys in current database |
| `KEYS *`         | List all keys (use with caution)   |
| `SCAN 0`         | Scan keys safely with cursor       |
| `CONFIG GET *`   | Get all configuration parameters   |
| `CLIENT LIST`    | List connected clients             |
| `SLOWLOG GET 10` | Recent slow log entries            |
| `MEMORY STATS`   | Memory usage statistics            |
| `TIME`           | Current server time                |

<Tip>
  Click any quick command to insert it into the input field, then press Enter to execute.
</Tip>

## Response Types

| Type        | Description            | Example                |
| ----------- | ---------------------- | ---------------------- |
| **string**  | Simple string response | `"OK"`, `"PONG"`       |
| **integer** | Numeric response       | `(integer) 42`         |
| **list**    | Array of values        | Numbered list of items |
| **dict**    | Key-value pairs        | Object properties      |
| **null**    | No value               | `(nil)`                |

## Common Commands

### Key Operations

| Command              | Description                 |
| -------------------- | --------------------------- |
| `GET key`            | Get value of a key          |
| `SET key value`      | Set key to value            |
| `DEL key`            | Delete a key                |
| `EXISTS key`         | Check if key exists         |
| `TYPE key`           | Get key type                |
| `TTL key`            | Get time to live in seconds |
| `EXPIRE key seconds` | Set expiration              |

### String Operations

| Command            | Description      |
| ------------------ | ---------------- |
| `SET key value`    | Set string value |
| `GET key`          | Get string value |
| `INCR key`         | Increment by 1   |
| `DECR key`         | Decrement by 1   |
| `APPEND key value` | Append to string |

### Hash Operations

| Command                | Description               |
| ---------------------- | ------------------------- |
| `HSET key field value` | Set hash field            |
| `HGET key field`       | Get hash field            |
| `HGETALL key`          | Get all fields and values |
| `HDEL key field`       | Delete hash field         |

### List Operations

| Command           | Description          |
| ----------------- | -------------------- |
| `LPUSH key value` | Push to left (head)  |
| `RPUSH key value` | Push to right (tail) |
| `LPOP key`        | Pop from left        |
| `RPOP key`        | Pop from right       |
| `LRANGE key 0 -1` | Get all elements     |

### Set Operations

| Command                | Description       |
| ---------------------- | ----------------- |
| `SADD key member`      | Add member to set |
| `SMEMBERS key`         | Get all members   |
| `SISMEMBER key member` | Check membership  |
| `SREM key member`      | Remove member     |

### Server Commands

| Command                      | Description                      |
| ---------------------------- | -------------------------------- |
| `INFO`                       | Server information               |
| `INFO memory`                | Memory section only              |
| `CONFIG GET parameter`       | Get config value                 |
| `CONFIG SET parameter value` | Set config value                 |
| `FLUSHDB`                    | Delete all keys in database      |
| `FLUSHALL`                   | Delete all keys in all databases |

<Warning>
  `FLUSHDB` and `FLUSHALL` permanently delete data. Use with extreme caution.
</Warning>

## How to Use Command History

<Steps>
  <Step title="Execute Commands">
    Run one or more commands during your session.
  </Step>

  <Step title="Navigate History">
    Press Arrow Up to recall previous commands.
  </Step>

  <Step title="Cycle Through">
    Continue pressing Arrow Up/Down to navigate through history.
  </Step>

  <Step title="Modify and Execute">
    Edit the recalled command if needed, then press Enter.
  </Step>
</Steps>

<Info>
  Command history is stored in your browser session. It clears when you close the browser or click Clear.
</Info>

## How to Copy Results

<Steps>
  <Step title="Execute Command">
    Run a command that returns results.
  </Step>

  <Step title="Click Copy">
    Click the copy icon next to the result.
  </Step>

  <Step title="Paste">
    The formatted result is now in your clipboard.
  </Step>
</Steps>

## How to Clear History

<Steps>
  <Step title="Click Clear">
    Click the **Clear** button in the header.
  </Step>

  <Step title="Confirm">
    All command history in the current session is removed.
  </Step>
</Steps>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Command returns error" icon="circle-question">
    * Check command syntax
    * Verify key exists (for read commands)
    * Check argument count and types
    * Some commands require specific Redis versions
  </Accordion>

  <Accordion title="Cannot execute commands" icon="circle-question">
    * You need write permission for CLI access
    * Check if connection is active
    * Verify network connectivity to Redis
  </Accordion>

  <Accordion title="Command taking too long" icon="circle-question">
    * Large dataset operations take time
    * KEYS \* on large databases is slow
    * Use SCAN instead of KEYS for large datasets
    * Check slow log for details
  </Accordion>

  <Accordion title="Unexpected response format" icon="circle-question">
    * Different commands return different types
    * Arrays show numbered lists
    * Nil means the key doesn't exist
    * Check Redis documentation for expected return type
  </Accordion>

  <Accordion title="History not persisting" icon="circle-question">
    * History is session-only, not persisted to server
    * Refreshing the page clears history
    * Use a local Redis CLI for persistent history
  </Accordion>

  <Accordion title="Cannot see write commands" icon="circle-question">
    * You need `iam:project:infrastructure:redis:write` permission
    * Contact your administrator for access
  </Accordion>
</AccordionGroup>

## FAQ

<AccordionGroup>
  <Accordion title="Is this the same as redis-cli?">
    This provides similar functionality to the `redis-cli` command-line tool but runs in your browser. It supports most commands but may not support interactive features like `MONITOR` or `SUBSCRIBE`.
  </Accordion>

  <Accordion title="Can I run multiple commands at once?">
    Commands are executed one at a time. For bulk operations, consider using scripts or the native redis-cli with pipelines.
  </Accordion>

  <Accordion title="Are my commands logged?">
    Commands may be logged for audit purposes. Avoid entering sensitive data like passwords in command arguments.
  </Accordion>

  <Accordion title="Why can't I use SUBSCRIBE or MONITOR?">
    These commands require persistent connections and streaming responses, which are not supported in this web interface. Use a native Redis client for these features.
  </Accordion>

  <Accordion title="What happens if I run FLUSHDB?">
    FLUSHDB deletes all keys in the current database immediately and permanently. There is no confirmation prompt. Use with extreme caution.
  </Accordion>

  <Accordion title="Can I script multiple commands?">
    Use Lua scripting with `EVAL` for atomic multi-command operations. Example: `EVAL "return redis.call('GET', KEYS[1])" 1 mykey`
  </Accordion>

  <Accordion title="How do I switch databases?">
    Use the database dropdown in the toolbar, or execute `SELECT <db-number>` command.
  </Accordion>

  <Accordion title="What commands are not supported?">
    Interactive commands (MONITOR, SUBSCRIBE, PSUBSCRIBE) and blocking commands with infinite timeout may not work properly in the web interface.
  </Accordion>
</AccordionGroup>

## Best Practices

### Safety

* Test commands on non-production first
* Avoid KEYS \* on large databases
* Use SCAN for iterating keys
* Never run FLUSHDB/FLUSHALL without verification
* Be careful with CONFIG SET changes

### Performance

* Use specific key patterns instead of wildcards
* Paginate large result sets
* Prefer EXISTS over GET for existence checks
* Use MGET/MSET for multiple keys

### Debugging

* Use TYPE to verify key types
* Check TTL to understand expiration
* Use OBJECT ENCODING for internal representation
* Review MEMORY USAGE for key size

### Commands to Avoid in Production

| Command    | Risk          | Alternative   |
| ---------- | ------------- | ------------- |
| `KEYS *`   | Blocks server | `SCAN`        |
| `FLUSHDB`  | Data loss     | Selective DEL |
| `FLUSHALL` | All data loss | None          |
| `DEBUG *`  | Server impact | INFO          |
| `SHUTDOWN` | Server stops  | Admin access  |
