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

Update the Persist Redis package information for Ballerina Central #9

Merged
merged 11 commits into from
Mar 29, 2024
Merged
91 changes: 72 additions & 19 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
# Overview

This module provide Redis database support for the `bal persist` feature, which provides functionality to store and query data from a
Redis database through a data model instead of writing Redis commands.
This module provides Redis database support for the `bal persist` feature, which provides functionality to store and query data from a Redis database through a data model instead of writing Redis commands.

Since Redis is not the default datastore for `bal persist` you need to explicitly specify the data store when initializing `bal persist` in your application. as follows,
## How to use with `bal persist`

```
$ bal persist init --datastore redis
```
Since Redis is not the default datastore for `bal persist` you need to explicitly specify the data store in your application in either of the following ways,

### Integrate to `bal build`

1. Initialize `bal persist` and integrate to `bal build` using the following command,

```
$ bal persist add --datastore redis --module <module_name>
```

2. After defining the entities, build the application using the following command,

```
$ bal build
```

### One time generation

1. Initialize `bal persist` using the following command,

```
$ bal persist init
```

2. Generate the persist client using the following command,

## Supported Ballerina Data Types
The following table lists the Ballerina data types supported by the Redis data store in `bal persist`. The specified data types will be converted to `string` during data insertion and then reverted to their original data types within Ballerina upon retrieval.
```
$ bal persist generate --datastore redis --module <module_name>
```

## Supported Ballerina data types

The following table lists the Ballerina data types supported by the Redis data store. Following data types will be converted to `string` when inserting data and converted back to relevent data types in ballerina when retrieving.

| Ballerina Type |
|:----------------:|
Expand All @@ -27,25 +53,52 @@ The following table lists the Ballerina data types supported by the Redis data s

## Configuration

You need to set values for the following basic configuration parameters in the `Config.toml` file in your project to use the Redis data store.
You need to set a value for the following configuration parameter in the `Config.toml` file in your project to use the Redis data store.

| Parameter | Description |
|:----------:|:------------------------------------:|
| host | The hostname of the DB server. |
| port | The port of the DB server. |
| password | The password of the DB server. |
| connection | The connection URI of the DB server. |

The following is a sample `Config.toml` file with the Redis data store configuration. This is generated by the `persist generate` command.

The following is a sample `Config.toml` file with the Redis data store configuration. This is generated by the `bal persist generate` command.
```toml
[<packageName>.<moduleName>.redis]
connection = "redis://localhost:6379"
```

Alternatively, you can provide connection parameters instead of the `URI` as follows.
```toml
[<packageName>.<moduleName>]
[<packageName>.<moduleName>.redis.connection]
host = "localhost"
port = 6379
password = ""
```

## How To Setup
Use docker as follows to create a DB server deployment.
Additionally, you can set values for the advanced configuration parameters in the Config.toml file in your project to use the Redis data store. For more information on these parameters, see the [Redis Connector documentation](https://central.ballerina.io/ballerinax/redis/latest#ConnectionConfig).

## Setup guide

Select one of the methods below to set up a Redis server.

### Setup a Redis server locally

Install a Redis server on your machine locally by downloading and installing it based on your development platform. See the [official Redis documentation](https://redis.io/download/).

### Setup using docker

Use Docker to create a DB server deployment.
1. Install Docker on your machine if you haven't already.
2. Pull the Redis Docker image from Docker Hub using the command `docker pull redis`.
3. Run the Redis container as follows `docker run -d -p 6379:6379 --name <container-name> redis`.

### Setup a cloud-based Redis service

* Run `docker pull redis` to pull the official Redis Docker image from the Docker Hub
* Run `docker run --name <your-redis-container-name> -p 6379:6379 -d redis`
Use a cloud-based DB solution such as Google’s Cloud, Amazon’s Web Services, or Microsoft’s Azure database.
1. Visit [Redis cloud console](https://app.redislabs.com).
2. Login using email and password or using one of the Single Sign-On options.
3. Select either Amazon Web Services, Google Cloud, or Microsoft Azure as the database vendor.
4. Select a region and create the database.
5. Find your `username`, `password` and the `public endpoint`
6. Replace the `connection` parameter in the `Config.toml` file as below

```toml
connection = "redis://<username>:<password>@<public_endpoint>"
90 changes: 72 additions & 18 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
# Overview

This module provide Redis database support for the `bal persist` feature, which provides functionality to store and query data from a Redis database through a data model instead of writing Redis commands.
This package provides Redis database support for the `bal persist` feature, which provides functionality to store and query data from a Redis database through a data model instead of writing Redis commands.

Since Redis is not the default datastore for `bal persist` you need to explicitly specify the data store when initializing `bal persist` in your application. as follows,
## How to use with `bal persist`

```
$ bal persist init --datastore redis
```
Since Redis is not the default datastore for `bal persist` you need to explicitly specify the data store in your application in either of the following ways,

### Integrate to `bal build`

1. Initialize `bal persist` and integrate to `bal build` using the following command,

```
$ bal persist add --datastore redis --module <module_name>
```

2. After defining the entities, build the application using the following command,

```
$ bal build
```

### One time generation

1. Initialize `bal persist` using the following command,

```
$ bal persist init
```

2. Generate the persist client using the following command,

```
$ bal persist generate --datastore redis --module <module_name>
```

## Supported Ballerina data types

## Supported Ballerina Data Types
The following table lists the Ballerina data types supported by the Redis data store. Following data types will be converted to `string` when inserting data and converted back to relevent data types in ballerina when retrieving.

| Ballerina Type |
Expand All @@ -26,32 +53,59 @@ The following table lists the Ballerina data types supported by the Redis data s

## Configuration

You need to set values for the following basic configuration parameters in the `Config.toml` file in your project to use the Redis data store.
You need to set a value for the following configuration parameter in the `Config.toml` file in your project to use the Redis data store.

| Parameter | Description |
|:----------:|:------------------------------------:|
| host | The hostname of the DB server. |
| port | The port of the DB server. |
| password | The password of the DB server. |
| connection | The connection URI of the DB server. |

The following is a sample `Config.toml` file with the Redis data store configuration. This is generated by the `persist generate` command.

The following is a sample `Config.toml` file with the Redis data store configuration. This is generated by the `bal persist generate` command.
```toml
[<packageName>.<moduleName>.redis]
connection = "redis://localhost:6379"
```

Alternatively, you can provide connection parameters instead of the `URI` as follows.
```toml
[<packageName>.<moduleName>]
[<packageName>.<moduleName>.redis.connection]
host = "localhost"
port = 6379
password = ""
```

## How To Setup
Use docker as follows to create a DB server deployment.
Additionally, you can set values for the advanced configuration parameters in the Config.toml file in your project to use the Redis data store. For more information on these parameters, see the [Redis Connector documentation](https://central.ballerina.io/ballerinax/redis/latest#ConnectionConfig).

## Setup guide

Select one of the methods below to set up a Redis server.

### Setup a Redis server locally

Install a Redis server on your machine locally by downloading and installing it based on your development platform. See the [official Redis documentation](https://redis.io/download/).

### Setup using docker

Use Docker to create a DB server deployment.
1. Install Docker on your machine if you haven't already.
2. Pull the Redis Docker image from Docker Hub using the command `docker pull redis`.
3. Run the Redis container as follows `docker run -d -p 6379:6379 --name <container-name> redis`.

### Setup a cloud-based Redis service

* Run `docker pull redis` to pull the official Redis Docker image from the Docker Hub
* Run `docker run --name <your-redis-container-name> -p 6379:6379 -d redis`
Use a cloud-based DB solution such as Google’s Cloud, Amazon’s Web Services, or Microsoft’s Azure database.
1. Visit [Redis cloud console](https://app.redislabs.com).
2. Login using email and password or using one of the Single Sign-On options.
3. Select either Amazon Web Services, Google Cloud, or Microsoft Azure as the database vendor.
4. Select a region and create the database.
5. Find your `username`, `password` and the `public endpoint`
6. Replace the `connection` parameter in `Config.toml` file as below

```toml
connection = "redis://<username>:<password>@<public_endpoint>"

## Report issues

To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina standard library parent repository](https://github.com/ballerina-platform/ballerina-standard-library).
To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina standard library parent repository](https://github.com/ballerina-platform/ballerina-library).

## Useful links
- Chat live with us via our [Discord server](https://discord.gg/ballerinalang).
Expand Down
Loading