org.mule.modules

mule-module-redis

config

Namespacehttp://www.mulesoft.org/schema/mule/redis
Schema Locationhttp://www.mulesoft.org/schema/mule/redis/current/mule-redis.xsd  (View Schema)
Schema Version3.4
Minimum Mule Version3.4.0

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 ObjectStore for Mule components that require persistence.

Summary

Configuration
<redis:config>
Configure an instance of this module
Message Sources
<redis:subscribe>
Subscribe to the specified channels.
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:decrement>
Decrements the number stored at key by step.
<redis:exists>
Test if the specified key exists.
<redis:expire>
Set a timeout on the specified key.
<redis:expire-at>
Set a timeout in the form of a UNIX timestamp (Number of seconds elapsed since 1 Jan 1970) on 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:get-ttl>
Get the remaining time to live in seconds of a volatile key.
<redis:increment>
Increments the number stored at key by step.
<redis:hash-increment>
Increments the number stored at field in the hash stored at key by increment.
<redis:sorted-set-increment>
Increments the score of member in the sorted set stored at key by increment.
<redis:persist>
Undo an expire or expireAt ; turning the volatile key into a normal 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.

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/current/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 necessary 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 ValueDescriptionJava TypeMIME TypeEncoding
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 defaultPartitionName Optional. The PartitionableObjectStore partition to use in case methods from ObjectStore are used.
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

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for SADD String */* UTF-8
mustSucceed false Optional. If true, ensures that adding to the set was successful (ie no pre-existing identical value in the set) boolean */*
value #[message.payloadAs(java.lang.String)] Optional. The value to set. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
byte[] 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

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for ZADD String */* UTF-8
score Score to use for the value double */*
mustSucceed false Optional. If true, ensures that adding to the sorted set was successful (ie no pre-existing identical value in the set) boolean */*
value #[message.payloadAs(java.lang.String)] Optional. The value to set. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
byte[] If no new entry has been added to the sorted set and mustSucceed is true, null is returned. Otherwise the message is returned.

<redis:decrement>

Decrements the number stored at key by step. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains data that can not be represented as integer.

XML Sample
INCLUDE_ERROR

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for DECR. String */* UTF-8
step 1 Optional. Step used for the increment. long */*
Returns
Return Type Description
Long A byte array with the content of the key

<redis:exists>

Test if the specified key exists.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for EXISTS String */* UTF-8
Returns
Return Type Description
Boolean A boolean that represents the existence of the key.

<redis:expire>

Set a timeout on the specified key.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key The key in the sorted set. String */* UTF-8
seconds The time to live in seconds. int */*
Returns
Return Type Description
Boolean true if EXPIRE was successful, false otherwise.

<redis:expire-at>

Set a timeout in the form of a UNIX timestamp (Number of seconds elapsed since 1 Jan 1970) on the specified key.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key The key in the sorted set. String */* UTF-8
unixTime The UNIX timestamp in seconds. long */*
Returns
Return Type Description
Boolean true if EXPIREAT was successful, false otherwise.

<redis:get>

Get the value of the specified key. If the key does not exist null is returned.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for GET String */* UTF-8
Returns
Return Type Description
byte[] 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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for HGET String */* UTF-8
field Field that will be used for HGET String */* UTF-8
Returns
Return Type Description
byte[] 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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for ZRANGE/ZREVRANGE String */* UTF-8
start Range start index int */*
end Range end index int */*
order ASCENDING Optional. Index order for sorting the range, either ASCENDING or DESCENDING RedisModule.SortedSetOrder */*
Returns
Return Type Description
Set<byte[]> the values in the specified range in the desired order as Set

<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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for ZRANGEBYSCORE/ZREVRANGEBYSCORE String */* UTF-8
min Range start score double */*
max Range end score double */*
order ASCENDING Optional. Score order for sorting the range, either ASCENDING or DESCENDING RedisModule.SortedSetOrder */*
Returns
Return Type Description
Set<byte[]> the values in the specified range in the desired order as Set

<redis:get-ttl>

Get the remaining time to live in seconds of a volatile key.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key The key in the sorted set. String */* UTF-8
Returns
Return Type Description
Long the remaining time to live in seconds, -2 when key does not exist or -1 when key does not have a timeout.

<redis:increment>

Increments the number stored at key by step. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains data that can not be represented as integer.

XML Sample
INCLUDE_ERROR

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for INCR. String */* UTF-8
step 1 Optional. Step used for the increment. long */*
Returns
Return Type Description
Long the incremented number.

<redis:hash-increment>

Increments the number stored at field in the hash stored at key by increment. If key does not exist, a new key holding a hash is created. If field does not exist the value is set to 0 before the operation is performed.

XML Sample
INCLUDE_ERROR

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for HGET String */* UTF-8
field Field that will be used for HGET String */* UTF-8
step 1 Optional. Step used for the increment. long */*
Returns
Return Type Description
Long the incremented number.

<redis:sorted-set-increment>

Increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.

XML Sample
INCLUDE_ERROR

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key The key in the sorted set. String */* UTF-8
step The step to use to increment the score. double */*
value #[message.payloadAs(java.lang.String)] Optional. The value to set. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
Double the new score of the member.

<redis:persist>

Undo an expire or expireAt ; turning the volatile key into a normal key.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key The key in the sorted set. String */* UTF-8
Returns
Return Type Description
Boolean true if PERSIST was successful, false otherwise.

<redis:list-pop>

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

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for LPOP/RPOP String */* UTF-8
side The side where to pop the value from, either LEFT or RIGHT RedisModule.ListPushSide */*
Returns
Return Type Description
byte[] 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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for SPOP String */* UTF-8
Returns
Return Type Description
byte[] 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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
channel Destination of the published message String */* UTF-8
mustSucceed false Optional. Enforces the fact that the message must have been delivered to at least one consumer boolean */*
message #[message.payloadAs(java.lang.String)] Optional. The message to publish. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
byte[] 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

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for LPUSH/RPUSH/LPUSHX/RPUSH String */* UTF-8
side The side where to push the payload, either LEFT or RIGHT RedisModule.ListPushSide */*
ifExists false Optional. If true execute LPUSHX/RPUSH otherwise LPUSH/RPUSH boolean */*
value #[message.payloadAs(java.lang.String)] Optional. The value to push. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
byte[] 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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for SRANDMEMBER String */* UTF-8
Returns
Return Type Description
byte[] 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

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key used to store payload String */* UTF-8
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. Integer */*
ifNotExists false Optional. If true, then execute SETNX on the Redis server, otherwise execute SET boolean */*
value #[message.payloadAs(java.lang.String)] Optional. The value to set. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
byte[] 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

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
key Key that will be used for HSET String */* UTF-8
field Field that will be used for HSET String */* UTF-8
ifNotExists false Optional. If true execute HSETNX otherwise HSET boolean */*
value #[message.payloadAs(java.lang.String)] Optional. The value to set. String */* UTF-8
muleEvent The current MuleEvent. MuleEvent */*
Returns
Return Type Description
byte[] 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
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
callback Called when messages arrive in any of the specified channels. SourceCallback */*
Child Elements
NameDefault ValueDescriptionJava Type
<redis:channels> A list of channel names or globbing patterns. List<String>

Transformers