DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stateless JWT Auth Microservice Architecture With Spring Boot 3 and Redis Sentinel
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  • When Kubernetes Breaks Session Consistency: Using Cosmos DB and Redis Together
  • Rate Limiting Strategies With Redis: Fixed Window, Sliding Window, and Token Bucket

Trending

  • Metal and Skins
  • Jakarta EE 12: Entering the Data Age of Enterprise Java
  • Engineering Closed-Loop Graph-RAG Systems, Part 2: From Prompts to Rules
  • Frame Buffer Hashing for Visual Regression on Embedded Devices
  1. DZone
  2. Software Design and Architecture
  3. Microservices
  4. Redis Connector in Mule 4

Redis Connector in Mule 4

For this article, I will be using a non-clustered connection to show you the basic operations of the Redis connector in Anypoint Studio.

By 
Kuldeep Rana user avatar
Kuldeep Rana
·
Jan. 23, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.7K Views

Join the DZone community and get the full member experience.

Join For Free

What is Redis?

Remote Dictionary Server (Redis) is an open-source, in-memory data structure store. It is used for various use cases such as caching a user profile, creating a leaderboard, tracking real-time activities on a website, implementing a spam filtering system, using it as a message queue, and more.

Redis is an open-source key-value store. It uses memory to store its data most of the time. It is fast because it stores data in memory instead of disk.

One can easily create their account by going to the Redis lab website and configuring the necessary details.

Configuring Details on Redis Labs

Once you have created your account, it will provide you with the endpoint and password that the Mulesoft Redis connector will use to use the Redis Database.

Redis Connector in Anypoint Studio

Redis Connector is not present in the Mule Palette by default. You need to go to the Palette and then search in exchange to get it in the studio and use it.

Adding Redis Connector Dependency

Make sure you always import the latest version of the connector from the exchange. Just click on the drop-down in the version column to see all the available versions of the connector.

Once the Redis connector is available in the studio, you can perform various operations provided by the connector by configuring the Redis connector with your Redis account.

Redis Inside the Mule Palette

Configuring the Redis Connector

Redis provides you with 3 types of connections to connect to your Redis database :

  1. Clustered
  2. Non-Clustered
  3. Sentinel

You can read more about the connections from the Mulesoft document provided here:

https://docs.mulesoft.com/redis-connector/5.4/redis-connector-reference#redis

For this article, I will be using a non-clustered connection to show you the basic operations of the Redis connector.

NonClustered Setting Within Global Element Properties

You need to provide the host, port, and password to get a successful connection for the non clustered connection for your Redis connector.

Various Operation in Redis Connector

As we have seen above, that Redis connector provides us with various operations to use. We will now be using some of them to know what they are basically used for and how they are configured.

SET

The SET operation is used to assign a value or payload to a key. If the key already holds a value, it is overwritten, regardless of its type.

Redis Connector Set Operation in Mule Flow

While using the connector, you need to specify both the key and the value.

You can also set the timeout on the specified key. After the timeout, the key will automatically be deleted from the database or server. A key with an associated timeout is said to be volatile in Redis Terminology.

You can set the expiration timeout just below the value box, as seen in the image above.

Once you trigger the above endpoint with the postman, you will get an OK response, which means the value has been successfully set in the Redis database.

GET

The GET operation is used to retrieve or get the value of a specified key. If the key does not exist, null is returned.

You need to pass the key in the connector configuration to retrieve the value of that key.

Redis Connector Get Operation in Mule Flow

Increment

The Increment operation is used to increment the number stored in the key by step. If the key does not exist, it is set to 0 before operating.

An error is returned if the key contains a wrong value or data that can not be represented in Integer.

Redis Connector Increment Operation in Mule Flow

You need to provide the key in the connector configuration for which you need to increment the value. The step option provides you the benefit of buying how much you need to increase the value of the key. Like above, the step is set to 2. Therefore, every time the endpoint is triggered, it will increase its value by 2 (+2).

Expire

The expire operation is used to expire a key present in Redis in a specified time interval also mentioned with the key in the connector configuration.

Redis Connector Expire Operation in Mule Flow

Here in the image above, as soon as the endpoint is triggered, the key count will expire in 10 seconds from the time of getting triggered. If the value of Seconds is set to 0(zero), it will expire instantly, without waiting even for 1 second.

DEL

The Del operation is used to Delete a specified key. The key is ignored if it does not exist.

You need to provide the key name in the connector configuration.

Redis Connector Del Operation in Mule Flow

Exists

The existing operation helps you to check if the specified key is present in the Redis or not.

It will output as true if the key is present, else false.

Redis Connector Exists Operation in Mule Flow

Likewise, you can try other Redis operations as well. Redis has been very beneficial in cases where more than 100 transactions per second as the Object Store in Mulesoft fails to provide you that.

Reference Links

https://docs.mulesoft.com/redis-connector/5.4/redis-connector-reference#redis

https://docs.mulesoft.com/redis-connector/5.4/

Redis (company) Connector (mathematics)

Published at DZone with permission of Kuldeep Rana. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Stateless JWT Auth Microservice Architecture With Spring Boot 3 and Redis Sentinel
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  • When Kubernetes Breaks Session Consistency: Using Cosmos DB and Redis Together
  • Rate Limiting Strategies With Redis: Fixed Window, Sliding Window, and Token Bucket

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook