From 56045a2933f94d655391318db67ab9dec9338f01 Mon Sep 17 00:00:00 2001 From: Divyansh Kulshreshtha Date: Sun, 20 Oct 2024 19:19:45 +0530 Subject: [PATCH 1/2] docs: enhanced documentation of the sleep command #832 --- docs/src/content/docs/commands/SLEEP.md | 51 +++++++++++-------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/docs/src/content/docs/commands/SLEEP.md b/docs/src/content/docs/commands/SLEEP.md index 59d29c9b2..49f2bd3a0 100644 --- a/docs/src/content/docs/commands/SLEEP.md +++ b/docs/src/content/docs/commands/SLEEP.md @@ -5,21 +5,26 @@ description: The `SLEEP` command in DiceDB is used to pause the execution of the The `SLEEP` command in DiceDB is used to pause the execution of the current client connection for a specified number of seconds. This command is primarily useful for testing purposes, such as simulating network latency or delaying operations to observe the behavior of other commands in a controlled environment. -## Parameters - -### Syntax +## Syntax ``` SLEEP seconds ``` -### Parameters +## Parameters + +| Parameter | Description | Type | Required | +|-----------|---------------------------------------------------------------------------|--------|----------| +| `seconds` | An integer representing the number of seconds to sleep. Only integers values are allowed. | Integer | Yes | -- `seconds`: (Required) A floating-point number representing the number of seconds to sleep. This value can be an integer or a decimal, allowing for sub-second precision. -## Return Value +## Return values + +| Condition | Return Value | +|-----------------------------------------|-------------------------------------------------| +| Command is successful | `OK` after specified sleep duration has elapsed | +| Syntax or specified datatype is invalid | error | -The `SLEEP` command returns a simple string reply of "OK" after the specified sleep duration has elapsed. ## Behaviour @@ -30,21 +35,19 @@ When the `SLEEP` command is executed, the following behavior is observed: 3. Other clients connected to the DiceDB server will not be affected and can continue to execute commands normally. 4. After the sleep duration has elapsed, the client will receive an "OK" response and can resume normal operations. -## Error Handling +## Errors The `SLEEP` command can raise errors under the following conditions: 1. `Invalid Number of Arguments`: - - - `Error Message`: `ERR wrong number of arguments for 'sleep' command` - - `Condition`: This error occurs if the `SLEEP` command is called without the required `seconds` parameter or with more than one parameter. + - Error Message: `ERR wrong number of arguments for 'sleep' command` + - Occurs if the `SLEEP` command is called without the required `seconds` parameter or with more than one parameter. 2. `Invalid Parameter Type`: + - Error Message: `ERR value is not an integer or out of range` + - Occurs if the `seconds` parameter is not a valid integer. - - `Error Message`: `ERR value is not a valid float` - - `Condition`: This error occurs if the `seconds` parameter is not a valid floating-point number. - -## Example Usage +## Examples ### Example 1: Basic Usage @@ -53,18 +56,10 @@ Pause the client for 5 seconds. ```shell 127.0.0.1:7379> SLEEP 5 OK +(5.01s) ``` -### Example 2: Sub-second Precision - -Pause the client for 1.5 seconds. - -```shell -127.0.0.1:7379> SLEEP 1.5 -OK -``` - -### Example 3: Error Handling - Missing Parameter +### Example 2: Error Handling - Missing Parameter Attempt to call `SLEEP` without specifying the `seconds` parameter. @@ -73,13 +68,13 @@ Attempt to call `SLEEP` without specifying the `seconds` parameter. (error) ERR wrong number of arguments for 'sleep' command ``` -### Example 4: Error Handling - Invalid Parameter Type +### Example 3: Error Handling - Invalid Parameter Type -Attempt to call `SLEEP` with a non-numeric parameter. +Attempt to call `SLEEP` with a non-integer parameter. ```shell 127.0.0.1:7379> SLEEP abc -(error) ERR value is not a valid float +(error) ERR value is not an integer or out of range ``` ## Notes From af3b596ae5786b351583182032562f7ab991c5e4 Mon Sep 17 00:00:00 2001 From: Divyansh Kulshreshtha Date: Sun, 20 Oct 2024 22:41:05 +0530 Subject: [PATCH 2/2] docs: minor changes in the sleep command --- docs/src/content/docs/commands/SLEEP.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/src/content/docs/commands/SLEEP.md b/docs/src/content/docs/commands/SLEEP.md index 49f2bd3a0..7ecd01cc2 100644 --- a/docs/src/content/docs/commands/SLEEP.md +++ b/docs/src/content/docs/commands/SLEEP.md @@ -7,7 +7,7 @@ The `SLEEP` command in DiceDB is used to pause the execution of the current clie ## Syntax -``` +```bash SLEEP seconds ``` @@ -56,7 +56,6 @@ Pause the client for 5 seconds. ```shell 127.0.0.1:7379> SLEEP 5 OK -(5.01s) ``` ### Example 2: Error Handling - Missing Parameter