Introduction

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

The Redis Connector offers complete support for its CRUD API.

Read through this user guide to understand how to set up and configure a basic flow using the connector. Track feature additions, compatibility, limitations and API version updates with each release of the connector using the Redis Release Notes. Review the connector operations and functionality using the Technical Reference alongside the demo applications.

MuleSoft maintains this connector under the Select support policy.

Prerequisites

Have a basic familiarity with Anypoint Connectors, and Anypoint Studio Essentials. To increase your familiarity with Studio, consider completing a Anypoint Studio Tutorial. This page requires some basic knowledge of Mule Concepts, Elements in a Mule Flow, and Global Elements.

Requirements

For hardware and software requirements, please visit the Hardware and Software Requirements page.

Namespace and Schema

When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.

If you are manually coding the Mule application in Studio’s XML editor or other text editor, paste these into the header of your Configuration XML, inside the <mule> tag.
1
2
3
4
5
6
7
8
<mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis"
  ...
  xsi:schemaLocation="http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/connector/current/mule-redis.xsd">
  ...
  <flow name="yourFlow">
  ...
  </flow>
</mule>

Using the Connector in a Mavenized Mule App

If you are coding a Mavenized Mule application, this XML snippet must be included in your pom.xml file.

1
2
3
4
5
<dependency>
  <groupId>org.mule.modules</groupId>
  <artifactId>mule-module-redis</artifactId>
  <version>RELEASE</version>
</dependency>
Inside the <version> tags, put the desired version number, the word RELEASE for the latest release, or SNAPSHOT for the latest available version.

Compatibility

Software Version

Mule Runtime

3.6.0 and higher

Redis server

2.8.x, 3.0.x and 3.2.x

Installing

You can install a connector in Anypoint Studio using the instructions in Installing a Connector from Anypoint Exchange.

Configuring

To use Redis connector in your Mule application, you must configure a global Redis element that can be used by all the connectors in the application (read more about global elements).

Below are the properties that you must provide to configure the global element:

Configuration

In the image above, the placeholder values refer to a configuration file placed in the src folder of your project (Learn how to configure properties). You can either hardcode your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better re-usability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ. See Deploying to Multiple Environments for instructions on how to manage this.
Field Description

Name

Enter a name for this configuration to reference it later.

Cluster Hosts

Redis cluster hosts, separated by comma and with the format host:port. Use this field when you want to access you Redis cluster through the connector.

Host

Redis host. Use this field when you want to access you Redis server that is not part of a cluster through the connector.

Connection Timeout

Connection timeout in milliseconds.

Port

Redis port. The port on which your non cluster server is running.

Default Partition Name

The partition name to use in case that the connector is used as a partitionable object store.

Password

Redis password. Set this in case that the server requires authentication.

Pool Config Reference

Object pool configuration. Reference to a bean of type redis.clients.jedis.JedisPoolConfig

Upgrading from an Older Version

If you’re currently using an older version of the connector, a small popup appears in the bottom right corner of Anypoint Studio with an "Updates Available" message.

  1. Click the popup and check for available updates. 

  2. Click the Connector version checkbox and click Next and follow the instructions provided by the user interface. 

  3. Restart Studio when prompted. 

  4. After restarting, when creating a flow and using the Object Store Connector, if you have several versions of the connector installed, you may be asked which version you would like to use. Pick one of these.

We recommend that you keep Studio up to date with the connector’s latest version. 

Using This Connector

You can use this connector as an inbound endpoint for consuming messages from a channel. You can subscribe to one of these channels through the connector or as an outbound connector for sending commands to the Redis server.

See the full list of operations for the latest version of the connector here.

Managing the Connection Pool

To define the pooling profile for the connector manually, access the Pooling Profile tab in the applicable global element for the connector.

For background information on pooling, see Tuning Performance.

Example Use Case

Save a value for a key into Redis server

This use case describes how to use the connector for assigning a value to a key into the Redis server.

  1. Create a new Mule Project by clicking File > New > Mule Project.

    New project menu

  2. In the new project dialog box, the only thing you are required to enter is a name for your new project. Click on Finish.

    New project dialog

  3. Navigate through the project’s structure and double-click on src/main/app/project-name.xml to open it. The steps below are all performed on this file:

  4. Go to the palette and search for "Http", then drag and drop a new Http Connector on canvas. This element shall be the entry point for the flow and will provide the key and value to be set for that key.

  5. Go to the palette and search for "Redis", then drag and drop a new Redis connector after "Http" connector. This element is going to send data to the Redis server.

  6. Go to the palette and search for "Set Payload", then drag and drop a new Set Payload element after the "Redis" connector. This element shall create the response for the incoming HTTP request.

    Unconfigured producer flow

  7. Double click on the flow’s top margin to open its properties, and change the name of the flow to "set-flow".

    Set flow configuration

  8. Double click on the HTTP Connector to open its properties.

    1. Click on the green plus sign along side the "Connector Configuration" drop down menu.

    2. A pop-up will appear, leave the default configurations and click ok.

    3. Set Path to "/value".

    4. Set Display Name to "Set value HTTP endpoint".

      Set HTTP configuration

  9. Double click on Redis and set its properties as below:

    1. Set Display Name to "Set value for key into Redis".

    2. Choose from the Consumer Configuration drop down "Redis__Configuration" (the default name of a configuration, or any other configuration that you configured as explained in the Configuring section)

    3. Choose from Operation drop down "Set".

    4. Set Key to "#[payload.key]".

    5. Set Value to "#[payload.value]".

      Redis set operation configuration

  10. Double click on Set Payload and set its properties as below.

    1. Set Display Name to "Set value response".

    2. Set Value to "Value successfully set.".

      Set HTTP response configuration

  11. If you configured Redis global element with placeholder values ( as explained within Configuring section) you must now provide values for these placeholders. Open /src/main/app/mule-app.properties and provide values for following properties: config.host, config.port and config.connectionTimeout

  12. Deploy the app.

  13. Once the app is running, send an HTTP request to it to trigger it’s flow. To do this, use the CURL command line utility or an HTTP client app (such as Postman) to send a POST request with content-type application/x-www-form-urlencoded and a body in urlencoded format to localhost:8081/value. The request’s body should contain a key and a value. For this you can use the following CURL command: curl -X POST -d "key=test-key" -d "value=test-value" localhost:8081/value.

  14. Congratulations! You have just set a value for a key into the redis server.

Save a value for a key into Redis server code

  1. Add the redis namespace to the mule element as follows:

    1
    
    xmlns:redis="http://www.mulesoft.org/schema/mule/redis"
  2. Add the location of the redis schema referred to by the "redis" namespace:

    1
    
    http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/sfdc-composite/current/mule-redis.xsd
  3. Add the HTTP namespace to the mule element as follows:

    1
    
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
  4. Add the location of the HTTP schema referred to by the HTTP namespace:

    1
    
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  5. Add a redis:config element to your project, then configure its attributes as follows:

    1
    
    <redis:config name="Redis__Configuration" host="${config.host}" connectionTimeout="${config.connectionTimeout}" port="${config.port}" doc:name="Redis: Configuration"/>
  6. Add a http:listener-config element to your project, then configure its attributes as follows:

    1
    
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
  7. Add an empty flow element to your project as follows:

    1
    2
    
    <flow name="set-flow">
    </flow>
  8. Within the flow element add an http:listener element as follows:

    1
    
    <http:listener config-ref="HTTP_Listener_Configuration" path="/value" doc:name="Set value HTTP endpoint"/>
  9. Within the flow element add a redis:set after the http:listener as follows:

    1
    
    <redis:set config-ref="Redis__Configuration" key="#[payload.key]" value="#[payload.value]" doc:name="Set value for key into Redis"/>
  10. Within the flow element add a set-payload element after redis:set as follows:

    1
    
    <set-payload value="Value successfully set." doc:name="Set value response"/>
  11. When you’re done, the XML file should look like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    <?xml version="1.0" encoding="UTF-8"?>
    
    <mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:apachekafka="http://www.mulesoft.org/schema/mule/apachekafka" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
            xmlns:spring="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/apachekafka http://www.mulesoft.org/schema/mule/apachekafka/current/mule-apachekafka.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
    http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/current/mule-redis.xsd">
        <redis:config name="Redis__Configuration" host="${config.host}" connectionTimeout="${config.connectionTimeout}" port="${config.port}" doc:name="Redis: Configuration"/>
        <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
        <flow name="set-flow">
            <http:listener config-ref="HTTP_Listener_Configuration" path="/value" doc:name="Set value HTTP endpoint"/>
            <redis:set config-ref="Redis__Configuration" key="#[payload.key]" value="#[payload.value]" doc:name="Set value for key into Redis"/>
            <set-payload value="Successfully set value: #[payload.value] to key: #[payload.key]" doc:name="Set value response"/>
        </flow>
    </mule>

Demos

The above explained example use case can be found within the common-commands-demo demo. Other operation examples also exist.

See Also