Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#773: Update PING cmd Docs #857

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 49 additions & 38 deletions docs/src/content/docs/commands/PING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ description: The `PING` command in DiceDB is used to test the connection between

The `PING` command in DiceDB is used to test the connection between the client and the DiceDB server. It's a crucial command for ensuring that the DiceDB server is reachable and functional. It is often utilized to check the health of the server and ensure that it is responsive.

## Parameters

The `PING` command can optionally take a single argument which is a string.

- `message`: Optional. A string that you want the DiceDB server to return as a response. If a message is provided, the DiceDB server will respond with the same message.

### Syntax
## Syntax

The basic syntax of the `PING` command is as follows:

Expand All @@ -22,58 +16,75 @@ PING [message]
- If `[message]` is provided, it will be echoed back in the response.
- If `[message]` is not provided, default response is `PONG`.

## Return Value
## Parameters

The return value varies based on the presence of the optional `[message]` parameter.
| Parameter | Description | Type | Required |
|-----------------|--------------------------------------------------|---------|----------|
| `message` | `message` echoed in the response | String | No |

- `No message provided`: If no message is provided, `PING` will return a simple string reply `PONG`.
- `Message provided`: If a message is provided, `PING` will return a simple string that echoes the given message.
## Return values

## Example Usage

### Example 1: Pinging the server without a message

```bash
127.0.0.1:7379> PING
PONG
```

### Example 2: Pinging the server with a message

```bash
127.0.0.1:7379> PING "Hello, DiceDB!"
"Hello, DiceDB!"
```
| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| No `message` provided | `PONG` |
| `message` provided | `message` |

## Behaviour

When the `PING` command is fired:

1. If no message is given, it sends back a `PONG`.
2. If a message is provided, it sends back the same message in the response.
- If no `message` is given, it sends back a `PONG`.
- If a `message` is provided, it sends back the same message in the response.
- If `message` provided is non-string value, the value is internally coerced to string and echoed as response.

This helps clients determine if the server is up and responsive. Essentially, it acts as a keep-alive or heartbeat mechanism for clients to validate their connection with the DiceDB server.

## Error Handling

### Potential Errors
## Errors

1. `Syntax Error`: If the syntax is incorrect, such as including unexpected additional parameters, an error will be raised:

- `Error message`: `(error) ERR wrong number of arguments for 'ping' command`
- `Scenario`: If more than one argument is provided.

```bash
> PING "Message 1" "Message 2"
127.0.0.1:7379> PING "Message 1" "Message 2"
(error) ERR wrong number of arguments for 'ping' command
```

2. `Data Type Error`: If the argument provided is not a string (for example, if a list or other data type is provided), a type error will be raised.
## Example Usage

- `Error message`: This specific type of error handling is internal, and improper types are generally implicitly converted or rejected by the protocol, raising basic syntax errors or allowing them based on DiceDB internal type coercion rules.
### Basic Usage

## Additional Notes
`PING` DiceDB server without a message and the server echoes with `PONG`.

- The `PING` command works similarly in both standalone and clustered DiceDB environments.
- It is typically sent periodically by clients to ensure the connection is still active.
- The `PING` command does not modify the data within the DiceDB server or affect any ongoing transactions.
```bash
127.0.0.1:7379> PING
PONG
```

### Pinging the server with a message

DiceDB server is pinged with `Hello, DiceDB!` and the server echoes with `Hello, DiceDB!`.

```bash
127.0.0.1:7379> PING "Hello, DiceDB!"
"Hello, DiceDB!"
```

### Pinging the server with int message

DiceDB server is pinged with `1234` and the server echoes with `"1234"` coerced to string internally.

```bash
127.0.0.1:7379> PING 1234
"1234"
```

### Pinging the server with list message

DiceDB server is pinged with `[1234]` and the server echoes with `"[1234]"` coerced to string internally.

```bash
127.0.0.1:7379> PING [1234]
"[1234]"
```
Loading