public class

RedisModule

extends Object
implements PartitionableObjectStore<T extends Serializable>
java.lang.Object
   ↳ org.mule.module.redis.RedisModule
Known Direct Subclasses
Known Indirect Subclasses

Class 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

Nested Classes
enum RedisModule.ListPushSide  
enum RedisModule.SortedSetOrder  
Constants
String DEFAULT_PARTITION_NAME
Fields
private static final Log LOGGER
private int connectionTimeout Connection timeout in milliseconds
private String host Redis host
private JedisPool jedisPool
private String password Redis password
private GenericObjectPool.Config poolConfig Object pool configuration
private int port Redis port
private int reconnectionFrequency Reconnection frequency in milliseconds
private boolean running
Public Constructors
RedisModule()
Public Methods
byte[] addToSet(String key, Boolean mustSucceed, byte[] message)
Add the message payload to the set stored at the specified key.
byte[] addToSortedSet(String key, Double score, Boolean mustSucceed, byte[] message)
Add the message payload with the desired score to the sorted set stored at the specified key.
List<Serializable> allKeys()
List<Serializable> allKeys(String partitionName)
List<String> allPartitions()
void close()
void close(String partitionName)
boolean contains(Serializable key, String partitionName)
boolean contains(Serializable key)
void destroyJedis()
void disposePartition(String partitionName)
byte[] get(String key)
Get the value of the specified key.
int getConnectionTimeout()
byte[] getFromHash(String key, String field)
Get the value stored at the specified field in the hash at the specified key.
String getHost()
JedisPool getJedisPool()
String getPassword()
GenericObjectPool.Config getPoolConfig()
int getPort()
Set<byte[]> getRangeByIndex(String key, Integer start, Integer end, RedisModule.SortedSetOrder order)
Retrieve a range of values from the sorted set stored at the specified key.
Set<byte[]> getRangeByScore(String key, Double min, Double max, RedisModule.SortedSetOrder order)
Retrieve a range of values from the sorted set stored at the specified key.
int getReconnectionFrequency()
void initializeJedis()
boolean isPersistent()
void open(String partitionName)
void open()
byte[] popFromList(String key, RedisModule.ListPushSide side)
Pop a value from the desired side of the list stored at the specified key.
byte[] popFromSet(String key)
Pops a random value from the set stored at the specified key.
byte[] publish(String channel, Boolean mustSucceed, byte[] message)
Publish the message payload to the specified channel.
byte[] pushToList(String key, RedisModule.ListPushSide side, Boolean ifExists, byte[] message)
Push the message payload to the desired side (LEFT or RIGHT) of the list stored at the specified key.
byte[] randomMemberFromSet(String key)
Reads a random value from the set stored at the specified key.
Serializable remove(Serializable key, String partitionName)
Serializable remove(Serializable key)
Serializable retrieve(Serializable key)
Serializable retrieve(Serializable key, String partitionName)
byte[] set(String key, Integer expire, Boolean ifNotExists, byte[] message)
Set key to hold the payload.
void setConnectionTimeout(int connectionTimeout)
void setHost(String host)
byte[] setInHash(String key, String field, Boolean ifNotExists, byte[] message)
Set the specified hash field to the message payload.
void setPassword(String password)
void setPoolConfig(GenericObjectPool.Config poolConfig)
void setPort(int port)
void setReconnectionFrequency(int reconnectionFrequency)
void store(Serializable key, Serializable value)
void store(Serializable key, Serializable value, String partitionName)
void subscribe(List<String> channels, SourceCallback callback)
Subscribe to the specified channels.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mule.api.store.ListableObjectStore
From interface org.mule.api.store.ObjectStore
From interface org.mule.api.store.PartitionableObjectStore

Constants

private static final String DEFAULT_PARTITION_NAME

Constant Value: "_default"

Fields

private static final Log LOGGER

private int connectionTimeout

Connection timeout in milliseconds

private String host

Redis host

private JedisPool jedisPool

private String password

Redis password

private GenericObjectPool.Config poolConfig

Object pool configuration

private int port

Redis port

private int reconnectionFrequency

Reconnection frequency in milliseconds

private boolean running

Public Constructors

public RedisModule ()

Public Methods

public byte[] addToSet (String key, Boolean mustSucceed, byte[] message)

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.

Parameters
key Key that will be used for SADD
mustSucceed 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
Returns
  • If no new entry has been added to the set and mustSucceed is true, null is returned. Otherwise the message is returned.

public byte[] addToSortedSet (String key, Double score, Boolean mustSucceed, byte[] message)

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.

Parameters
key Key that will be used for ZADD
score Score to use for the value
mustSucceed 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
Returns
  • If no new entry has been added to the sorted set and mustSucceed is true, null is returned. Otherwise the message is returned.

public List<Serializable> allKeys ()

Throws
ObjectStoreException

public List<Serializable> allKeys (String partitionName)

Parameters
partitionName
Throws
ObjectStoreException

public List<String> allPartitions ()

Throws
ObjectStoreException

public void close ()

Throws
ObjectStoreException

public void close (String partitionName)

Parameters
partitionName
Throws
ObjectStoreException

public boolean contains (Serializable key, String partitionName)

Parameters
key
partitionName
Throws
ObjectStoreException

public boolean contains (Serializable key)

Parameters
key
Throws
ObjectStoreException

public void destroyJedis ()

public void disposePartition (String partitionName)

Parameters
partitionName
Throws
ObjectStoreException

public byte[] get (String key)

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.

Parameters
key Key that will be used for GET
Returns
  • A byte array with the content of the key

public int getConnectionTimeout ()

public byte[] getFromHash (String key, String field)

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.

Parameters
key Key that will be used for HGET
field Field that will be used for HGET
Returns
  • The value or null.

public String getHost ()

public JedisPool getJedisPool ()

public String getPassword ()

public GenericObjectPool.Config getPoolConfig ()

public int getPort ()

public Set<byte[]> getRangeByIndex (String key, Integer start, Integer end, RedisModule.SortedSetOrder order)

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.

Parameters
key Key that will be used for ZRANGE/ZREVRANGE
start Range start index
end Range end index
order Index order for sorting the range, either ASCENDING or DESCENDING
Returns
  • the values in the specified range in the desired order

public Set<byte[]> getRangeByScore (String key, Double min, Double max, RedisModule.SortedSetOrder order)

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.

Parameters
key Key that will be used for ZRANGEBYSCORE/ZREVRANGEBYSCORE
min Range start score
max Range end score
order Score order for sorting the range, either ASCENDING or DESCENDING
Returns
  • the values in the specified range in the desired order

public int getReconnectionFrequency ()

public void initializeJedis ()

public boolean isPersistent ()

public void open (String partitionName)

Parameters
partitionName
Throws
ObjectStoreException

public void open ()

Throws
ObjectStoreException

public byte[] popFromList (String key, RedisModule.ListPushSide side)

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

Parameters
key Key that will be used for LPOP/RPOP
side The side where to pop the value from, either LEFT or RIGHT
Returns
  • The popped value or null if either the list is empty or no list exists at the key

public byte[] popFromSet (String key)

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

Parameters
key Key that will be used for SPOP
Returns
  • The popped value or null if either the set is empty or no set exists at the key

public byte[] publish (String channel, Boolean mustSucceed, byte[] message)

Publish the message payload to the specified channel.

Parameters
channel Destination of the published message
mustSucceed 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
Returns
  • If no consumer is subscribed to the channel and mustSucceed is true, null is returned. Otherwise the message is returned.

public byte[] pushToList (String key, RedisModule.ListPushSide side, Boolean ifExists, byte[] message)

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.

Parameters
key Key that will be used for LPUSH/RPUSH/LPUSHX/RPUSH
side The side where to push the payload, either LEFT or RIGHT
ifExists If true execute LPUSHX/RPUSH otherwise LPUSH/RPUSH
message The payload of the message as a byte array
Returns
  • If the key doesn't already exist and ifExists is true, null is returned. Otherwise the message is returned.

public byte[] randomMemberFromSet (String key)

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

Parameters
key Key that will be used for SRANDMEMBER
Returns
  • The random value or null if either the set is empty or no set exists at the key

public Serializable remove (Serializable key, String partitionName)

Parameters
key
partitionName
Throws
ObjectStoreException

public Serializable remove (Serializable key)

Parameters
key
Throws
ObjectStoreException

public Serializable retrieve (Serializable key)

Parameters
key
Throws
ObjectStoreException

public Serializable retrieve (Serializable key, String partitionName)

Parameters
key
partitionName
Throws
ObjectStoreException

public byte[] set (String key, Integer expire, Boolean ifNotExists, byte[] message)

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.

Parameters
key Key used to store payload
expire 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 If true, then execute SETNX on the Redis server, otherwise execute SET
message The payload of the message as a byte array
Returns
  • If the key already exists and ifNotExists is true, null is returned. Otherwise the message is returned.

public void setConnectionTimeout (int connectionTimeout)

Parameters
connectionTimeout

public void setHost (String host)

Parameters
host

public byte[] setInHash (String key, String field, Boolean ifNotExists, byte[] message)

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.

Parameters
key Key that will be used for HSET
field Field that will be used for HSET
ifNotExists If true execute HSETNX otherwise HSET
message The payload of the message as a byte array
Returns
  • If the field already exists and ifNotExists is true, null is returned, otherwise if a new field is created the message is returned.

public void setPassword (String password)

Parameters
password

public void setPoolConfig (GenericObjectPool.Config poolConfig)

Parameters
poolConfig

public void setPort (int port)

Parameters
port

public void setReconnectionFrequency (int reconnectionFrequency)

Parameters
reconnectionFrequency

public void store (Serializable key, Serializable value)

Parameters
key
value
Throws
ObjectStoreException

public void store (Serializable key, Serializable value, String partitionName)

Parameters
key
value
partitionName
Throws
ObjectStoreException

public void subscribe (List<String> channels, SourceCallback callback)

Subscribe to the specified channels.

Parameters
channels A list of channel names or globbing patterns.
callback Called when messages arrive in any of the specified channels.