Configuring DB connectors - Redis

Studio enables you to use the database connectors to connect to your NoSQL databases like MongoDB, CouchDB, DynamoDB, Redis, and so on.

Redis is used as a distributed, in-memory key-value database. Redis uses abstract data structures, such as strings, lists, maps, etc. It is best suited for developers who need quick responses.

Configuring Redis connector

To add a DB connector, under Studio > Connectors, click (+) Connector.

You need to first configure the database. Enter the Connector name which would be used when you need the connector in your apps and while adding queries.

The most important part of the process is to provide the Connection strings. You can add the connection details or then provide the Connection string fields required for establishing a database connection.

For the Redis database you need to provide the following:

  • Host: Enter the correct Hostname
  • Port: Enter the Port name
  • Database number: Is the number assigned to the database
  • Password: The Integration with Redis supports password-based authentication.
  • WhiteList IP: You can enable WhitelistIP to specify that DronaHQ is permitted to connect to the Redis database by white-list the specified IP address.

Once these configurations are added, click Test Connection. If the authentication is successful you would get the response accordingly. Click Save to Finish configuration.

Adding queries to the Database connector

Now that you have configured the connector you will find it under the Connectors list. Now to fetch data or undertake any other action, click the Add query option available once your connection is ready.

Here you will have a list of Actions that you can carry out like Get, Set, Update, Delete, and so on.

You can provide a name to the query using Enter a Service name. Add your query and click Run or press Ctrl + enter to run the query. The rows returned from the database are shown in the Response section.

You can also add dynamic values using the Variables. To add the variable, click Variables > +Add. Add the FieldName and select the ****. Add a Test Value to check the results before saving. You can also add a Default Field type value or make it Mandatory. Add the Help text that would be shown with the field. Once you have entered the details, click Add Variable. The variable would be listed under Variables. You can make use of the variable in the query where you created the variable.

To use a variable inside a query, you simply need to put it into double Curly brackets. The Test value that you entered would be considered for fetching data. When using the connector queries the dynamic variables would have to be linked to the respective control for further run-time functioning.

You can now view the queries that you saved for use in your apps later under your specific connector under Database connectors.

Using Redis connector

Get a record

Now let us take a simple example to scan a Redis document and get a record with the Key provided dynamically. You can display the data in a textinput control. In this case, you simply need to select the action as Get and pass the dynamic variable using Double curly brackets. A sample is shown in the illustration below.

Add the query as seen above and run to verify the output. Once done Save the query. In this example, we have provided the test value as “F” so the output is the Value that is set for Key name ‘F’.

Now under Bind Data, you can use this query to get data. Add a text control that accepts the key to search. Then, add a textinput control or a dropdown control and configure the Connector to fetch the value set for the Key name “F”. Go to Bind Data> Connectors and configure the query.

In the example, we would be providing the keyname(textinput control) as a dynamic value using the Keywords.

Once you have provided the necessary parameters, Test and Finish the configuration of the connector. Now to fetch the record for the textinput control, use the result.rows to get the data returned.

getkey

So now when you take a preview of the respective form you would be able to see the data accordingly.

review

Get all keys

Let us consider an example to get all keys. In this case, you simply need to select the type of action as Keys as per the Redis syntax. Now that you want to get all the keys, we would provide the pattern here using “*” as the special character for all keys.

You can then configure the query to display data in a control like the dropdown control. Go to Bind Data> Connectors and configure the query.

Once you have provided the necessary parameters, Test and Finish configuration of the connector. Now to fetch the records for the dropdown control, use the result.rows to get the data returned.
getalldatakeys

Now when you run the query you would get the data from the document to the dropdown control.

allkeys preview

Set Value

Now if you want to insert data to your document you can use the Set action for the same by passing the respective values using the Key and Value. You can fetch it from your form and assign the respective values using the dynamic variables.

In this example, you would be accepting the data from a form and adding it on the Click of your Action button. Hence you will configure the Connector from the Action Flow > Server Side actions and add the respective controls as Keywords.

So whenever you run your form and click to submit data, the action flow would be triggered and the Connector will enable you to add data to your Redis database.

In this example, for the sake of understanding, we have used a tablegrid for the above Get Data connector to show the Value for the Keyname that was added to your Document.

Delete record

Similarly to delete data from your database you would have to choose Action as deleteItem and provide the key to delete the item using the dynamic variable. It could be any scenario like entering a “id” from the Textinput control and fetching the ID and adding the action flow to delete the record.

In this example you would be accepting the data from a form and adding it on the Click of your Action button. Hence you will configure the Connector from the Action Flow > Server Side actions and add the respective controls as Keywords.

So now whenever you run the form you can see that the record is deleted.