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

docs: improve consistency in PFCOUNT documentation #915

Merged
merged 1 commit into from
Oct 2, 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
73 changes: 39 additions & 34 deletions docs/src/content/docs/commands/PFCOUNT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ The `PFCOUNT` command in DiceDB is used to return the approximate cardinality (i

## Syntax

```plaintext
```
PFCOUNT key [key ...]
```

## Parameters

- `key`: The key(s) of the HyperLogLog data structure(s) whose cardinality you want to estimate. You can specify one or more keys.
| Parameter | Description | Type | Required |
|-----------|-------------|------|----------|
| `key` | The key(s) of the HyperLogLog data structure(s) whose cardinality you want to estimate. You can specify one or more keys. | String | Yes |

## Return Value
## Return Values

- `Integer`: The command returns an integer that represents the approximate number of unique elements observed in the specified HyperLogLog data structure(s).
| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| The specified `key` exists and contains a valid HyperLogLog | The estimated number of unique elements as an integer |
| The `key` does not exist or is not a valid HyperLogLog | `0` |

## Behaviour

Expand All @@ -27,59 +32,59 @@ When the `PFCOUNT` command is executed, DiceDB will:
2. Estimate the cardinality of the set(s) represented by the HyperLogLog data structure(s).
3. If multiple keys are specified, DiceDB will merge the HyperLogLog data structures and return the cardinality of the union of the sets.

## Example Usage

### Single Key

```plaintext
127.0.0.1:6379> PFADD hll1 "foo" "bar" "baz"
(integer) 1
127.0.0.1:6379> PFCOUNT hll1
(integer) 3
```

### Multiple Keys

```plaintext
127.0.0.1:6379> PFADD hll1 "foo" "bar"
(integer) 1
127.0.0.1:6379> PFADD hll2 "baz" "qux"
(integer) 1
127.0.0.1:6379> PFCOUNT hll1 hll2
(integer) 4
```

## Error Handling
## Errors

The `PFCOUNT` command can raise errors in the following scenarios:

1. `Non-Existent Key`: If the specified key does not exist, DiceDB will treat it as an empty HyperLogLog and return a cardinality of 0.

```plaintext
127.0.0.1:6379> PFCOUNT non_existent_key
```bash
127.0.0.1:7379> PFCOUNT non_existent_key
(integer) 0
```

2. `Wrong Type of Key`: If the specified key exists but is not a HyperLogLog data structure, DiceDB will return a type error.

`Error Message`: `WRONGTYPE Operation against a key holding the wrong kind of value`

```plaintext
127.0.0.1:6379> SET mykey "value"
```bash
127.0.0.1:7379> SET mykey "value"
OK
127.0.0.1:6379> PFCOUNT mykey
127.0.0.1:7379> PFCOUNT mykey
(error) WRONGTYPE Operation against a key holding the wrong kind of value
```

3. `Invalid Arguments`: If the command is called with no arguments, DiceDB will return a syntax error.

`Error Message`: `ERR wrong number of arguments for 'pfcount' command`

```plaintext
127.0.0.1:6379> PFCOUNT
```bash
127.0.0.1:7379> PFCOUNT
(error) ERR wrong number of arguments for 'pfcount' command
```

## Examples

### Single Key

```bash
127.0.0.1:7379> PFADD hll1 "foo" "bar" "baz"
(integer) 1
127.0.0.1:7379> PFCOUNT hll1
(integer) 3
```

### Multiple Keys

```bash
127.0.0.1:7379> PFADD hll1 "foo" "bar"
(integer) 1
127.0.0.1:7379> PFADD hll2 "baz" "qux"
(integer) 1
127.0.0.1:7379> PFCOUNT hll1 hll2
(integer) 4
```

## Notes

- The `PFCOUNT` command provides an approximate count, not an exact count. The error rate is typically less than 1%.
Expand Down
Loading