Skip to content

Commit

Permalink
docs: audit and make documentation for command SELECT (#1041)
Browse files Browse the repository at this point in the history
bagmeg authored Oct 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 45434f4 commit b0de463
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions docs/src/content/docs/commands/SELECT.md
Original file line number Diff line number Diff line change
@@ -3,31 +3,39 @@ title: SELECT
description: Documentation for the DiceDB command SELECT
---

**Note:** As of today, DiceDB does not support multiple databases. Therefore, the `SELECT` command is currently a dummy method and does not affect the database. It remains as a placeholder.

The `SELECT` command is used to switch the currently selected database for the current connection in DiceDB. By default, DiceDB starts with database 0, but it supports multiple databases, which can be accessed by using the `SELECT` command. This command is essential for managing data across different logical databases within a single DiceDB instance.

## Parameters
## Syntax

### index
```
SELECT index
```

- `Type`: Integer
- `Description`: The zero-based index of the database to select. DiceDB databases are indexed starting from 0 up to a configurable maximum (default is 15, configurable via the `databases` configuration directive).
- `Constraints`: Must be a non-negative integer within the range of available databases.
## Parameters

| Parameter | Description | Type | Required |
|-----------|-------------------------------------------------|---------|----------|
| `index` | The zero-based index of the database to select. DiceDB databases are indexed starting from 0 up to a configurable maximum (default is 15, configurable via the `databases` configuration directive) | Integer | Yes |

## Return Value

- `Type`: Simple String
- `Description`: Returns `OK` if the database switch was successful.
| Condition | Return Value |
|--------------------------|--------------|
| Command is successful | `OK` |

## Behaviour

When the `SELECT` command is issued, the current connection's context is switched to the specified database. All subsequent commands will operate on the selected database until another `SELECT` command is issued or the connection is closed.

- `Initial State`: By default, the connection starts with database 0.
- `Post-Command State`: The connection will be associated with the specified database index.
- The number of databases is configurable in the DiceDB configuration file (`DiceDB.conf`) using the `databases` directive.
- Switching databases does not affect the data stored in other databases; it only changes the context for the current connection.
- The `SELECT` command is connection-specific. Different connections can operate on different databases simultaneously.

## Error Handling

The `SELECT` command can raise errors under the following conditions:
## Errors

1. `Invalid Database Index`:

@@ -44,7 +52,7 @@ The `SELECT` command can raise errors under the following conditions:
### Switching to Database 1

```shell
127.0.0.1:6379> SELECT 1
127.0.0.1:7379> SELECT 1
OK
```

@@ -53,7 +61,7 @@ In this example, the connection switches to database 1. All subsequent commands
### Switching to Database 0

```shell
127.0.0.1:6379> SELECT 0
127.0.0.1:7379> SELECT 0
OK
```

@@ -62,7 +70,7 @@ Here, the connection switches back to the default database 0.
### Error Example: Invalid Database Index

```shell
127.0.0.1:6379> SELECT 16
127.0.0.1:7379> SELECT 16
(error) ERR DB index is out of range
```

@@ -71,17 +79,8 @@ In this example, an error is raised because the specified database index 16 is o
### Error Example: Non-Integer Index

```shell
127.0.0.1:6379> SELECT one
127.0.0.1:7379> SELECT one
(error) ERR value is not an integer or out of range
```

In this example, an error is raised because the provided index is not a valid integer.

## Notes

- The number of databases is configurable in the DiceDB configuration file (`DiceDB.conf`) using the `databases` directive.
- Switching databases does not affect the data stored in other databases; it only changes the context for the current connection.
- The `SELECT` command is connection-specific. Different connections can operate on different databases simultaneously.

By understanding and using the `SELECT` command, you can efficiently manage and segregate data across multiple logical databases within a single DiceDB instance.

0 comments on commit b0de463

Please sign in to comment.