Skip to content

Commit

Permalink
Merge pull request DiceDB#1537 from DiceDB/arpit-readiness-cli-chat
Browse files Browse the repository at this point in the history
Splitting documentation into sections.
  • Loading branch information
arpitbbhayani authored Feb 28, 2025
2 parents a026b0f + c53ff46 commit 0c27d69
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 141 deletions.
6 changes: 4 additions & 2 deletions docs/src/content/docs/commands/DECR.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ DECR command decrements the integer at 'key' by one. Creates 'key' as -1 if abse
Errors on wrong type or non-integer string. Limited to 64-bit signed integers.

Returns the new value of 'key' on success.


## Examples
#### Examples

```
localhost:7379> SET k 43
OK OK
localhost:7379> DECR k
OK 42
```
```
6 changes: 4 additions & 2 deletions docs/src/content/docs/commands/DECRBY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ DECRBY command decrements the integer at 'key' by the delta specified. Creates '
Errors on wrong type or non-integer string. Limited to 64-bit signed integers.

Returns the new value of 'key' on success.


## Examples
#### Examples

```
localhost:7379> SET k 43
OK OK
localhost:7379> DECRBY k 10
OK 33
```
```
7 changes: 3 additions & 4 deletions docs/src/content/docs/commands/DEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ description: DEL deletes all the specified keys
DEL key [key ...]
```


DEL command deletes all the specified keys and returns the number of keys deleted on success.

## Examples
#### Examples

```
localhost:7379> SET k1 v1
localhost:7379> SET k1 v1
OK OK
localhost:7379> SET k2 v2
OK OK
localhost:7379> DEL k1 k2 k3
OK 2
```

7 changes: 3 additions & 4 deletions docs/src/content/docs/commands/ECHO.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ description: ECHO returns the message passed to it
ECHO message
```


ECHO command returns the message passed to it.

## Examples
#### Examples

```
localhost:7379> ECHO hello!
localhost:7379> ECHO hello!
OK hello!
```

95 changes: 14 additions & 81 deletions docs/src/content/docs/commands/EXISTS.md
Original file line number Diff line number Diff line change
@@ -1,97 +1,30 @@
---
title: EXISTS
description: The `EXISTS` command in DiceDB is used to determine if one or more specified keys exist in the database. It returns the number of keys that exist among the specified ones.
description: EXISTS returns the count of keys that exist among the given
---

The `EXISTS` command in DiceDB is used to determine if one or more specified keys exist in the database. It returns the number of keys that exist among the specified ones.
<!-- This file is automatically generated. Any modifications made directly to this file
may be overwritten. For more details on how this file is generated and how to use
the related commands, refer to the documentation available in the `internal/cmd/cmd_*.go` files.
-->

## Syntax
#### Syntax

```bash
```
EXISTS key [key ...]
```

## Parameters

| Parameter | Description | Type | Required |
| --------- | ------------------------------------------------------------------------------------------ | ------ | -------- |
| `key` | The key(s) to check for existence. One or more keys can be specified, separated by spaces. | String | Yes |

## Return values

| Condition | Return Value |
| -------------------------------- | ------------------------------------------------- |
| None of the specified keys exist | `0` |
| One or more specified keys exist | Integer representing the count of keys that exist |

## Behaviour

- The `EXISTS` command checks whether the specified keys are present in the database.
- Returns 1 or 0, or for multiple keys returns the count of existing keys.
- The command performs a read-only operation and does not modify the database.

## Errors
EXISTS command returns the count of keys that exist among the given arguments without modifying them.

1. `Wrong number of arguments`:
#### Examples

- Error Message: `(error) ERR wrong number of arguments for 'exists' command`
- Occurs when no key is provided.

2. `Wrong type of value or key`:
- Error Message: `(error) WRONGTYPE Operation against a key holding the wrong kind of value`
- Occurs when attempting to use the command on a key that contains a non-string value.

## Example Usage

### Single Key Check

Checking if a key `mykey` exists in the database:

```bash
127.0.0.1:7379> SET mykey "Hello"
OK
127.0.0.1:7379> EXISTS mykey
(integer) 1
```
### Multiple Keys Check

Checking if multiple keys (`key1`, `key2`, `key3`) exist in the database:

```bash
127.0.0.1:7379> SET key1 "value1"
localhost:7379> SET k1 v1
OK
127.0.0.1:7379> SET key2 "value2"
localhost:7379> SET k2 v2
OK
127.0.0.1:7379> EXISTS key1 key2 key3
(integer) 2
```

In this case, `key1` and `key2` exist, but `key3` does not.

### Non-Existent Key

Checking if a non-existent key (`nonExistentKey`) is present in the database:

```bash
127.0.0.1:7379> EXISTS nonExistentKey
(integer) 0
```

### All Non-Existent Keys

Checking if all non-existent keys return 0:

```bash
127.0.0.1:7379> EXISTS nonExistentKey1 nonExistentKey2
(integer) 0
```

### Empty Command

Providing no keys should trigger an error:

```bash
127.0.0.1:7379> EXISTS
(error) ERR wrong number of arguments for 'exists' command
localhost:7379> EXISTS k1 k2 k3
OK 2
```
11 changes: 4 additions & 7 deletions internal/cmd/cmd_decr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ import (

var cDECR = &CommandMeta{
Name: "DECR",
HelpShort: "DECR decrements the value of the specified key in args by 1",
Syntax: "DECR key",
Documentation: `
HelpShort: "DECR decrements the value of the specified key in args by 1",
HelpLong: `
DECR command decrements the integer at 'key' by one. Creates 'key' as -1 if absent.
Errors on wrong type or non-integer string. Limited to 64-bit signed integers.
Returns the new value of 'key' on success.
## Examples
` + "```" + `
`,
Examples: `
localhost:7379> SET k 43
OK OK
localhost:7379> DECR k
OK 42
` + "```" + `
`,
Eval: evalDECR,
Execute: executeDECR,
Expand Down
11 changes: 4 additions & 7 deletions internal/cmd/cmd_decrby.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ import (

var cDECRBY = &CommandMeta{
Name: "DECRBY",
HelpShort: "DECRBY decrements the specified key by the specified delta",
Syntax: "DECRBY key delta",
Documentation: `
HelpShort: "DECRBY decrements the specified key by the specified delta",
HelpLong: `
DECRBY command decrements the integer at 'key' by the delta specified. Creates 'key' with value (-delta) if absent.
Errors on wrong type or non-integer string. Limited to 64-bit signed integers.
Returns the new value of 'key' on success.
## Examples
` + "```" + `
`,
Examples: `
localhost:7379> SET k 43
OK OK
localhost:7379> DECRBY k 10
OK 33
` + "```" + `
`,
Eval: evalDECRBY,
Execute: executeDECRBY,
Expand Down
16 changes: 5 additions & 11 deletions internal/cmd/cmd_del.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ import (

var cDEL = &CommandMeta{
Name: "DEL",
HelpShort: "DEL deletes all the specified keys",
Syntax: "DEL key [key ...]",
Documentation: `
DEL command deletes all the specified keys and returns the number of keys deleted on success.
## Examples
` + "```" + `
localhost:7379> SET k1 v1
HelpShort: "DEL deletes all the specified keys",
HelpLong: `DEL command deletes all the specified keys and returns the number of keys deleted on success.`,
Examples: `
localhost:7379> SET k1 v1
OK OK
localhost:7379> SET k2 v2
OK OK
localhost:7379> DEL k1 k2 k3
OK 2
` + "```" + `
`,
OK 2`,
Eval: evalDEL,
Execute: executeDEL,
}
Expand Down
16 changes: 5 additions & 11 deletions internal/cmd/cmd_echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ import (

var cECHO = &CommandMeta{
Name: "ECHO",
HelpShort: "ECHO returns the message passed to it",
Syntax: "ECHO message",
Documentation: `
ECHO command returns the message passed to it.
## Examples
` + "```" + `
localhost:7379> ECHO hello!
OK hello!
` + "```" + `
`,
HelpShort: "ECHO returns the message passed to it",
HelpLong: `ECHO command returns the message passed to it.`,
Examples: `
localhost:7379> ECHO hello!
OK hello!`,
Eval: evalECHO,
Execute: executeECHO,
}
Expand Down
16 changes: 13 additions & 3 deletions internal/cmd/cmd_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ import (

var cEXISTS = &CommandMeta{
Name: "EXISTS",
HelpShort: "Returns the count of keys that exist among the given arguments without modifying them",
Eval: evalEXISTS,
Execute: executeEXISTS,
Syntax: "EXISTS key [key ...]",
HelpShort: "EXISTS returns the count of keys that exist among the given",
HelpLong: `EXISTS command returns the count of keys that exist among the given arguments without modifying them.`,
Examples: `
localhost:7379> SET k1 v1
OK
localhost:7379> SET k2 v2
OK
localhost:7379> EXISTS k1 k2 k3
OK 2
`,
Eval: evalEXISTS,
Execute: executeEXISTS,
}

func init() {
Expand Down
15 changes: 8 additions & 7 deletions internal/cmd/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/dicedb/dicedb-go/wire"
)

// nolint: stylecheck
//nolint: stylecheck
const INFINITE_EXPIRATION = int64(-1)

type Cmd struct {
Expand Down Expand Up @@ -67,12 +67,13 @@ type CmdRes struct {
}

type CommandMeta struct {
Name string
HelpShort string
Syntax string
Documentation string
Eval func(c *Cmd, s *store.Store) (*CmdRes, error)
Execute func(c *Cmd, sm *shardmanager.ShardManager) (*CmdRes, error)
Name string
HelpShort string
Syntax string
Examples string
HelpLong string
Eval func(c *Cmd, s *store.Store) (*CmdRes, error)
Execute func(c *Cmd, sm *shardmanager.ShardManager) (*CmdRes, error)
}

type CmdRegistry struct {
Expand Down
8 changes: 7 additions & 1 deletion scripts/generate-docs/doc.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ description: {{ .HelpShort }}
{{ .Syntax }}
```

{{ .Documentation }}
{{ .HelpLong }}

#### Examples

```
{{ .Examples }}
```
2 changes: 1 addition & 1 deletion scripts/generate-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func generateDocs(tmpl *template.Template, c *cmd.CommandMeta) {
func main() {
tmpl := template.Must(template.ParseFiles("scripts/generate-docs/doc.tmpl"))
for _, c := range cmd.CommandRegistry.CommandMetas {
if c.Documentation == "" {
if c.HelpLong == "" {
continue
}

Expand Down

0 comments on commit 0c27d69

Please sign in to comment.