1. Home
  2. Examples
  3. Redis Cache Example

Redis Cache Example

This guide walks you through the process of caching using the Redis Cache tool in Warewolf.

For this example, we will be caching outputs generated from the SQL Server Database tool. This will be cached for 60 seconds. We will use a variable generated from the inputs of the workflow as the key used to cache the data.

Getting Started

Create a Redis Docker Container
Docker Redis Url: https://hub.docker.com/_/redis/
Docker Command: Pull Request: docker pull redis

Follow these simple steps below:

1.Click New to create a new workflow.

New Workflow

2. Drag and drop the Assign Tool onto the design surface.
Add a variable [[sales_data_month]]
Assign Sales-[[month]][[year]] to the [[sales_data_month]] variable.

assign_create_key

3. Mark [[month]] and [[year]] as Input. These are the parameters required for the stored procedure used later in the example.

assign_create_key_mark_inputs4. Search for the Redis in the Tool Box.

Drag Redis Cache Tool onto surface

5.Drag and drop the Redis Cache onto the design surface. The tool will open in large view.Redis Cache Tool

6. If you have not already configured your data source, Click New.

7. Add your Host Name, click Test Connection.

For more information on creating a new Redis Source check out Adding a New Redis Source

Enter Host Name and Click test Connection

8. Click Save in the menu on the left. In the popup dialog, name your Redis Source and Save.

9. Go back to your original workflow. Double click on the Redis Cache to open it in large view.

From the Source, select the Source that you want to connect to. In this example we connect to an Example Redis Source.

Select Redis Source from Dropdown

10. Once you have selected your Redis Source, enter the key. For this example we are using the variable [[sales_data_month]] created in the Assign tool earlier.

cache_key_name

11. The Time To Live will default to 5 seconds. If you want to change this then enter a new Time To Live.
cache_ttl

12. Drag and drop the SQL Server Database tool into the Drop Activity Here section. It will open in a large view. Configure the tool to execute the stored procedure that will return the data you would like to cache.
cache_sql_server_results

13. Click Done.

cache_sql_server_results_min

You will notice the recordset generated from the outputs of the added SQL Server Database tool is now displayed in the Variables List.

cache_sql_server_results_variables

14. Add in the Error recordset [[Error().Message]]. Errors returned from the Redis Cache will be written into this recordset.

To end the workflow, if an error has occurred at this point, make sure the End this workflow checkbox is selected.

Click Done.

cache_add_error_done15. In the Variables list, select the Errors recordset as outputs.

cache_add_error_variables16. When you have configured the Redis Cache Tool, Click Done. It will now look like this:

Redis Cache Final Workflow

17. Click Save. Name your Workflow and save.

18. Execute the Workflow by clicking F5. Enter values for the debug Inputs [[month]] and [[year]] configured in Step 3. You will then see the following in the Outputs window.

cache_debug_outputs_1

You will notice the SQL Server Database Tool has executed with an output recordset of [[regional_sales_data(*)]]

In the Redis Cache you will see that the key Sales-062020 was not found so [[regional_sales_data(*)]] was saved into the newly created key Sales-062020.

19. Execute the workflow again but be sure to execute it within the Time To Live.

If you set 60 seconds, execute within 60 seconds.
The outputs will now have this:

cache_debug_outputs_2jpg

You will notice it no longer displays the SQL Server Database execution, instead it has
pulled the cached data from the Redis Cache using the key Sales062020.

FacebookTwitterLinkedInGoogle+Email
Updated on July 8, 2020

Was this article helpful?

Related Articles

Enjoying Warewolf?

Write a review on G2 Crowd
Stars