org.mule.modules

mule-module-redis

3.2.1
Namespacehttp://www.mulesoft.org/schema/mule/redis
Schema Locationhttp://www.mulesoft.org/schema/mule/redis/3.2/mule-redis.xsd
Version3.2
Minimum Mule Version3.2

Module Overview

Redis is an open-source, networked, in-memory, persistent, journaled, key-value data store. Provides Redis connectivity to Mule:

  • Supports Redis Publish/Subscribe model for asynchronous message exchanges,
  • Allows direct reading and writing operations in Redis collections,
  • Allows using Redis as a datastore for Mule components that require persistence.

Summary

Configuration
<redis:config>
Configure an instance of this module
Message Processors
<redis:set-add>
Add the message payload to the set stored at the specified key.
<redis:sorted-set-add>
Add the message payload with the desired score to the sorted set stored at the specified key.
<redis:get>
Get the value of the specified key.
<redis:hash-get>
Get the value stored at the specified field in the hash at the specified key.
<redis:sorted-set-select-range-by-index>
Retrieve a range of values from the sorted set stored at the specified key.
<redis:sorted-set-select-range-by-score>
Retrieve a range of values from the sorted set stored at the specified key.
<redis:list-pop>
Pop a value from the desired side of the list stored at the specified key.
<redis:set-pop>
Pops a random value from the set stored at the specified key.
<redis:publish>
Publish the message payload to the specified channel.
<redis:list-push>
Push the message payload to the desired side (LEFT or RIGHT) of the list stored at the specified key.
<redis:set-fetch-random-member>
Reads a random value from the set stored at the specified key.
<redis:set>
Set key to hold the payload.
<redis:hash-set>
Set the specified hash field to the message payload.
Message Sources
<redis:subscribe>
Subscribe to the specified channels.

Configuration

To use the this module within a flow the namespace to the module must be included. The resulting flow will look similar to the following:

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:redis="http://www.mulesoft.org/schema/mule/redis"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core
               http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/redis
               http://www.mulesoft.org/schema/mule/redis/3.2/mule-redis.xsd">

      <!-- here goes your flows and configuration elements -->

</mule>

This module is configured using the config element. This element must be placed outside of your flows and at the root of your Mule application. You can create as many configurations as you deem necesary as long as each carries its own name.

Each message processor, message source or transformer carries a config-ref attribute that allows the invoker to specify which configuration to use.

Attributes
TypeNameDefault ValueDescription
xs:string name Optional. Give a name to this configuration so it can be later referenced.
xs:int connectionTimeout 2000 Optional. Connection timeout in milliseconds
xs:string host localhost Optional. Redis host
xs:string password Optional. Redis password
poolConfig Optional. Object pool configuration
xs:int port 6379 Optional. Redis port
xs:int reconnectionFrequency 5000 Optional. Reconnection frequency in milliseconds

Message Processors

<redis:set-add>

Add the message payload to the set stored at the specified key. If key does not exist, a new key holding a set is created.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for SADD
mustSucceed Optional. If true, ensures that adding to the set was successful (ie no pre-existing identical value in the set)
message The payload of the message as a byte array
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • If no new entry has been added to the set and mustSucceed is true, null is returned. Otherwise the message is returned.

<redis:sorted-set-add>

Add the message payload with the desired score to the sorted set stored at the specified key. If key does not exist, a new key holding a sorted set is created.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for ZADD
score Score to use for the value
mustSucceed Optional. If true, ensures that adding to the sorted set was successful (ie no pre-existing identical value in the set)
message The payload of the message as a byte array
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • If no new entry has been added to the sorted set and mustSucceed is true, null is returned. Otherwise the message is returned.

<redis:get>

Get the value of the specified key. If the key does not exist null is returned. If the value stored at key is not a string an error is returned because GET can only handle string values.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for GET
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • A byte array with the content of the key

<redis:hash-get>

Get the value stored at the specified field in the hash at the specified key. If the field or the hash don't exist, null is returned.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for HGET
field Field that will be used for HGET
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • The value or null.

<redis:sorted-set-select-range-by-index>

Retrieve a range of values from the sorted set stored at the specified key. The range of values is defined by indices in the sorted set and sorted as desired.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for ZRANGE/ZREVRANGE
start Range start index
end Range end index
order Optional. Index order for sorting the range, either ASCENDING or DESCENDING
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • the values in the specified range in the desired order

<redis:sorted-set-select-range-by-score>

Retrieve a range of values from the sorted set stored at the specified key. The range of values is defined by scores in the sorted set and sorted as desired.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for ZRANGEBYSCORE/ZREVRANGEBYSCORE
min Range start score
max Range end score
order Optional. Score order for sorting the range, either ASCENDING or DESCENDING
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • the values in the specified range in the desired order

<redis:list-pop>

Pop a value from the desired side of the list stored at the specified key.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for LPOP/RPOP
side The side where to pop the value from, either LEFT or RIGHT
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • The popped value or null if either the list is empty or no list exists at the key

<redis:set-pop>

Pops a random value from the set stored at the specified key.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for SPOP
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • The popped value or null if either the set is empty or no set exists at the key

<redis:publish>

Publish the message payload to the specified channel.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
channel Destination of the published message
mustSucceed Optional. Enforces the fact that the message must have been delivered to at least one consumer
message The payload of the message as a byte array
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • If no consumer is subscribed to the channel and mustSucceed is true, null is returned. Otherwise the message is returned.

<redis:list-push>

Push the message payload to the desired side (LEFT or RIGHT) of the list stored at the specified key. If key does not exist, a new key holding a list is created as long as ifExists is not true.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for LPUSH/RPUSH/LPUSHX/RPUSH
side The side where to push the payload, either LEFT or RIGHT
ifExists Optional. If true execute LPUSHX/RPUSH otherwise LPUSH/RPUSH
message The payload of the message as a byte array
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • If the key doesn't already exist and ifExists is true, null is returned. Otherwise the message is returned.

<redis:set-fetch-random-member>

Reads a random value from the set stored at the specified key.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for SRANDMEMBER
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • The random value or null if either the set is empty or no set exists at the key

<redis:set>

Set key to hold the payload. If key already holds a value, it is overwritten, regardless of its type as long as ifNotExists is false.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key used to store payload
expire Optional. Set a timeout on the specified key. After the timeout the key will be automatically deleted by the server. A key with an associated timeout is said to be volatile in Redis terminology.
ifNotExists Optional. If true, then execute SETNX on the Redis server, otherwise execute SET
message The payload of the message as a byte array
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • If the key already exists and ifNotExists is true, null is returned. Otherwise the message is returned.

<redis:hash-set>

Set the specified hash field to the message payload. If key does not exist, a new key holding a hash is created as long as ifNotExists is true.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
key Key that will be used for HSET
field Field that will be used for HSET
ifNotExists Optional. If true execute HSETNX otherwise HSET
message The payload of the message as a byte array
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements
Return Payload
  • If the field already exists and ifNotExists is true, null is returned, otherwise if a new field is created the message is returned.

Message Sources

<redis:subscribe>

Subscribe to the specified channels.


XML Sample
INCLUDE_ERROR

Attributes
config-ref Optional. Specify which configuration to use.
channels A list of channel names or globbing patterns.
callback Called when messages arrive in any of the specified channels.
retryMax 1 Optional. Specify how many times this operation can be retried automatically
Child Elements