Contact Us 1-800-596-4880

Redis Additional Configuration Information - Mule 4

Save a Value for a Key into a Redis Server

This use case describes how to use the connector to assign a value to a key in the Redis server.

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

  2. In the new project dialog box, provide a name for your new project. Click Finish.

    redis new proj
  3. Navigate through the project’s structure and double click src/main/mule/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 a new HTTP Connector Listener operation to the canvas. This element is the entry point for the flow and provides the key and value to be set for that key.

  5. Go to the palette and search for Redis, then drag a new Redis Set operation after the HTTP connector. This element sends data to the Redis server.

  6. Double click the Redis Set operation and set its properties as follows:

    1. Set Display Name to Set Value For Key Into Redis.

    2. Choose from the Extension Configuration drop down Redis__Configuration, which is the default name of a configuration, or any other configuration that you configured.

    3. Choose Set from the Operation drop down.

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

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

      redis set config
  7. Go to the palette and search for Set Payload, then drag a new Set Payload element after the Redis Connector. This element creates the response for the incoming HTTP request.

    redis set raw flow
  8. Double click the flow’s top margin to open its properties, and change the name of the flow to set-flow.

    redis set flow config
  9. Double click the HTTP Connector Listener operation to open its properties.

    1. Click the green plus sign beside the Connector Configuration field.

    2. A pop-up appears. Leave the default configuration and click OK.

    3. Set Path to /.

    4. Set Display Name to Listener.

      redis set http config
  10. Double click Set Payload and set its properties.

    1. Set Display Name to Set Value Response.

    2. Set Value to Value Successfully Set.

      redis set response config
  11. If you configured a Redis global element with placeholder values, provide values for the placeholders. Open /src/main/resources/ and provide values for following properties:, config.port, and config.connectionTimeout.

  12. Deploy the app.

  13. Once the app is running, send an HTTP request to it to trigger its flow. 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 url-encoded format to localhost:8081/. The request 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/

    Congratulations! You have just set a value for a key in the Redis server.

View on GitHub