Camel Components

Spring Redis

Since Camel 2.11

Both producer and consumer are supported

This component allows sending and receiving messages from Redis. Redis is an advanced key-value store where keys can contain strings, hashes, lists, sets and sorted sets. In addition, it provides pub/sub functionality for inter-app communications. Camel provides a producer for executing commands, consumer for subscribing to pub/sub messages an idempotent repository for filtering out duplicate messages.

Prerequisites

To use this component, you must have a Redis server running.

URI Format

spring-redis://host:port[?options]

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Spring Redis component supports the following options which are listed below.

Name Description Default Type

redisTemplate (common)

Autowired The org.springframework.data.redis.core.RedisTemplate that the producers of the endpoints of this component run the commands with, unless an endpoint sets its own redisTemplate. Autowired from the registry when it has exactly one RedisTemplate.

RedisTemplate

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The Spring Redis endpoint is configured using URI syntax:

spring-redis:host:port

With the following path and query parameters:

Path Parameters

Name Description Default Type

host (common)

Required The host name or IP address of the Redis server. The endpoint connects to it with the JedisConnectionFactory that it creates when connectionFactory is not set, and does not use it otherwise. If not set, localhost is used.

localhost

String

port (common)

Required The port of the Redis server. The endpoint connects to it with the JedisConnectionFactory that it creates when connectionFactory is not set, and does not use it otherwise. If not set, 6379 is used.

6379

Integer

Query Parameters

Name Description Default Type

command (common)

The Redis command that the producer runs, such as GET, SET or HSET. The CamelRedis.Command header replaces this option for a message. The consumer needs SUBSCRIBE or PSUBSCRIBE and fails to start with any other command, including the default SET. The producer fails a message with SUBSCRIBE, PSUBSCRIBE or a server command that it does not run, such as AUTH, FLUSHDB, INFO or SELECT.

Enum values:

  • PING

  • SET

  • GET

  • QUIT

  • EXISTS

  • DEL

  • TYPE

  • FLUSHDB

  • KEYS

  • RANDOMKEY

  • RENAME

  • RENAMENX

  • RENAMEX

  • DBSIZE

  • EXPIRE

  • EXPIREAT

  • TTL

  • SELECT

  • MOVE

  • FLUSHALL

  • GETSET

  • MGET

  • SETNX

  • SETEX

  • MSET

  • MSETNX

  • DECRBY

  • DECR

  • INCRBY

  • INCR

  • APPEND

  • SUBSTR

  • HSET

  • HGET

  • HSETNX

  • HMSET

  • HMGET

  • HINCRBY

  • HEXISTS

  • HDEL

  • HLEN

  • HKEYS

  • HVALS

  • HGETALL

  • RPUSH

  • LPUSH

  • LLEN

  • LRANGE

  • LTRIM

  • LINDEX

  • LSET

  • LREM

  • LPOP

  • RPOP

  • RPOPLPUSH

  • SADD

  • SMEMBERS

  • SREM

  • SPOP

  • SMOVE

  • SCARD

  • SISMEMBER

  • SINTER

  • SINTERSTORE

  • SUNION

  • SUNIONSTORE

  • SDIFF

  • SDIFFSTORE

  • SRANDMEMBER

  • ZADD

  • ZRANGE

  • ZREM

  • ZINCRBY

  • ZRANK

  • ZREVRANK

  • ZREVRANGE

  • ZCARD

  • ZSCORE

  • MULTI

  • DISCARD

  • EXEC

  • WATCH

  • UNWATCH

  • SORT

  • BLPOP

  • BRPOP

  • AUTH

  • SUBSCRIBE

  • PUBLISH

  • UNSUBSCRIBE

  • PSUBSCRIBE

  • PUNSUBSCRIBE

  • ZCOUNT

  • ZRANGEBYSCORE

  • ZREVRANGEBYSCORE

  • ZREMRANGEBYRANK

  • ZREMRANGEBYSCORE

  • ZUNIONSTORE

  • ZINTERSTORE

  • SAVE

  • BGSAVE

  • BGREWRITEAOF

  • LASTSAVE

  • SHUTDOWN

  • INFO

  • MONITOR

  • SLAVEOF

  • CONFIG

  • STRLEN

  • SYNC

  • LPUSHX

  • PERSIST

  • RPUSHX

  • ECHO

  • LINSERT

  • DEBUG

  • BRPOPLPUSH

  • SETBIT

  • GETBIT

  • SETRANGE

  • GETRANGE

  • PEXPIRE

  • PEXPIREAT

  • GEOADD

  • GEODIST

  • GEOHASH

  • GEOPOS

  • GEORADIUS

  • GEORADIUSBYMEMBER

SET

Command

connectionFactory (common)

The org.springframework.data.redis.connection.RedisConnectionFactory that connects to Redis. The endpoint uses it for the RedisTemplate and the listener container that it creates, and then does not use host and port. If not set, the endpoint creates a JedisConnectionFactory for host and port, and destroys it when the endpoint shuts down.

RedisConnectionFactory

serializer (common)

The org.springframework.data.redis.serializer.RedisSerializer for keys and values. The endpoint sets it as the default serializer of the RedisTemplate that it creates, and the consumer deserializes the body of each message with it. If not set, a JdkSerializationRedisSerializer is used, which stores keys and values in Java serialized form: use a StringRedisSerializer to work with text. The producer does not use it when a redisTemplate is set.

RedisSerializer

channels (consumer)

The channels that the consumer subscribes to, separated by comma. With the PSUBSCRIBE command they are patterns, such as news.*, and with SUBSCRIBE channel names. Required by the consumer. The producer does not use it: PUBLISH takes the channel from the CamelRedis.Channel header.

String

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

listenerContainer (consumer (advanced))

The org.springframework.data.redis.listener.RedisMessageListenerContainer that the consumer subscribes to the channels with. If not set, the endpoint creates and starts one on connectionFactory, and destroys it when the endpoint shuts down.

RedisMessageListenerContainer

redisTemplate (producer)

The org.springframework.data.redis.core.RedisTemplate that the producer runs the commands with, which also decides how keys and values are serialized. If not set, the redisTemplate of the component is used, and if that is not set either, the endpoint creates a RedisTemplate from connectionFactory and serializer. The consumer does not use it.

RedisTemplate

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

deserializationFilter (security)

An ObjectInputFilter pattern, in jdk.serialFilter syntax, that the default JdkSerializationRedisSerializer applies when it deserializes a value: the body of a message that the consumer receives, and a value that the producer reads with the RedisTemplate that the endpoint creates. If not set, the JVM-wide jdk.serialFilter is used when present, otherwise a default filter that rejects java.net., allows only java., javax. and org.apache.camel., and limits the depth, references and size of the object graph. Not used when serializer is set.

String

Message Headers

The Spring Redis component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelRedis.Command (producer)

Constant: COMMAND

The name of the Redis command that the producer runs, such as GET or HSET, in any case. Replaces the command option for this message.

String

CamelRedis.Key (producer)

Constant: KEY

The key that the command works on, used by most commands, such as GET, SET, HSET, LPUSH, SADD and ZADD. For SDIFF, SINTER, SUNION, their STORE forms, ZINTERSTORE and ZUNIONSTORE, the first key, which is combined with the keys of the CamelRedis.Keys header.

String

CamelRedis.Keys (producer)

Constant: KEYS

The keys to delete for DEL and to watch for WATCH, and for SDIFF, SINTER, SUNION, their STORE forms, ZINTERSTORE and ZUNIONSTORE the keys that are combined with the key of the CamelRedis.Key header. A collection of keys, or a String with one key or several keys separated by comma.

Collection or String

CamelRedis.Field (producer)

Constant: FIELD

The field of the hash for HDEL, HEXISTS, HGET, HINCRBY, HSET and HSETNX.

String

CamelRedis.Fields (producer)

Constant: FIELDS

The fields of the hash to read for HMGET, and the keys to read for MGET.

Collection

CamelRedis.Value (producer)

Constant: VALUE

The value for the commands that store, add or look up one value or member, such as SET, SETNX, GETSET, HSET, LPUSH, SADD, SISMEMBER, ZADD and GEOADD. It is a Long for INCRBY, DECRBY and HINCRBY, a Boolean for SETBIT, the new name of the key for RENAME and RENAMENX, and text for APPEND and ECHO. The serializer of the RedisTemplate writes it, so with the default JDK serializer it must be Serializable.

Object

CamelRedis.Values (producer)

Constant: VALUES

A Map of keys to values for MSET and MSETNX, and of fields to values for HMSET. For GEODIST, a Collection whose first two elements are the members to measure the distance between.

Map

CamelRedis.Start (producer)

Constant: START

The index of the first element for LRANGE, LTRIM, ZRANGE, ZREVRANGE and ZREMRANGEBYRANK, the offset of the first byte for GETRANGE, and the minimum score for ZREMRANGEBYSCORE when CamelRedis.Min is not set. Indexes start at 0, and a negative index counts from the end.

Long

CamelRedis.End (producer)

Constant: END

The index of the last element, inclusive, for LRANGE, LTRIM, ZRANGE, ZREVRANGE and ZREMRANGEBYRANK, the offset of the last byte for GETRANGE, and the maximum score for ZREMRANGEBYSCORE when CamelRedis.Max is not set. Indexes start at 0, and a negative index counts from the end, so -1 is the last element.

Long

CamelRedis.Timeout (producer)

Constant: TIMEOUT

The time to live of the key in seconds for EXPIRE and SETEX, and in milliseconds for PEXPIRE. For BLPOP, BRPOP and BRPOPLPUSH, how many seconds to wait for an element while the list is empty.

Long

CamelRedis.Offset (producer)

Constant: OFFSET

The offset of the bit for GETBIT and SETBIT, and the offset in bytes where SETRANGE writes the value.

Long

CamelRedis.Destination (producer)

Constant: DESTINATION

The key that receives the result for RPOPLPUSH, BRPOPLPUSH, SMOVE, SDIFFSTORE, SINTERSTORE, SUNIONSTORE, ZINTERSTORE and ZUNIONSTORE.

String

CamelRedis.Channel (common)

Constant: CHANNEL

The channel that PUBLISH posts the message to. The consumer sets it to the name of the channel that the message was received on.

String

CamelRedis.Message (producer)

Constant: MESSAGE

The message that PUBLISH posts to the channel of the CamelRedis.Channel header. The serializer of the RedisTemplate writes it, so with the default JDK serializer it must be Serializable.

Object

CamelRedis.Index (producer)

Constant: INDEX

The index of the element of the list for LINDEX and LSET. Indexes start at 0, and a negative index counts from the end, so -1 is the last element.

Long

CamelRedis.Position (producer)

Constant: POSITION

Where LINSERT inserts the value: BEFORE or AFTER the pivot, in upper case.

String

CamelRedis.Pivot (producer)

Constant: PIVOT

The element of the list that LINSERT inserts the value before or after.

String

CamelRedis.Count (producer)

Constant: COUNT

For LREM, how many elements equal to the value to remove: a positive count removes from the head, a negative count from the tail, and 0 removes all of them. For GEORADIUS and GEORADIUSBYMEMBER, the maximum number of members to return; if not set, all of them are returned.

Long

CamelRedis.Timestamp (producer)

Constant: TIMESTAMP

The time when the key expires, in seconds since the epoch for EXPIREAT and in milliseconds since the epoch for PEXPIREAT.

Long

CamelRedis.Pattern (common)

Constant: PATTERN

The glob-style pattern of the keys that KEYS returns, such as user:*. With the PSUBSCRIBE command, the consumer sets it, as a byte array, to the pattern of the channels option that the channel of the message matched.

byte[] or String

CamelRedis.Db (producer)

Constant: DB

The index of the database that MOVE moves the key to.

Integer

CamelRedis.Score (producer)

Constant: SCORE

The score of the member that ZADD adds.

Double

CamelRedis.Min (producer)

Constant: MIN

The minimum score, inclusive, for ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE and ZREMRANGEBYSCORE.

Double

CamelRedis.Max (producer)

Constant: MAX

The maximum score, inclusive, for ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE and ZREMRANGEBYSCORE.

Double

CamelRedis.Increment (producer)

Constant: INCREMENT

The amount that ZINCRBY adds to the score of the member.

Double

CamelRedis.WithScore (producer)

Constant: WITHSCORE

Whether ZRANGE and ZREVRANGE return the members together with their scores, as a Set of ZSetOperations.TypedTuple. If not set or false, they return the members only.

Boolean

CamelRedis.Latitude (producer)

Constant: LATITUDE

The latitude of the member that GEOADD adds, and of the center of the area that GEORADIUS searches.

Double

CamelRedis.Longitude (producer)

Constant: LONGITUDE

The longitude of the member that GEOADD adds, and of the center of the area that GEORADIUS searches.

Double

CamelRedis.Radius (producer)

Constant: RADIUS

The radius in meters of the area that GEORADIUS and GEORADIUSBYMEMBER search.

Double

Message Body

The message body at each side of the Spring Redis component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

unknown

The message as the serializer reads it: with the default JDK serializer the Java object the publisher serialized, such as the String a PUBLISH of this component sent, with the channel in the CamelRedis.Channel header. A message the serializer cannot read, such as text from redis-cli, is given as its raw bytes: set a StringRedisSerializer as the serializer to receive text.

Producer input

any

The body is not used: the key, the value and the other arguments of the command come from headers, such as CamelRedis.Key and CamelRedis.Value, or CamelRedis.Channel and CamelRedis.Message for PUBLISH. Set CamelRedis.Value from the body to store the body: with the default serializer it must be Serializable, so a stream fails.

Producer output

unchanged

The result of the command, which the CamelRedis.Command header can pick instead of the command option: SET, the default, PUBLISH and the other commands without a result keep the body; a Boolean or a number for those that test, count or increment, a Set or a List for those that read several members, a Map for HGETALL, and the stored object, which can be anything, for GET, HGET, LINDEX, LPOP, RPOP, SPOP and the other commands that read or pop one value: these are not known. These set the body to null when there is no value, such as GET of a missing key. An unknown command, or one the producer does not run, fails.

  • With command=SET: unchanged

  • With command=SETEX: unchanged

  • With command=MSET: unchanged

  • With command=HSET: unchanged

  • With command=HMSET: unchanged

  • With command=HDEL: unchanged

  • With command=DEL: unchanged

  • With command=PUBLISH: unchanged

  • With command=LSET: unchanged

  • With command=LTRIM: unchanged

  • With command=RENAME: unchanged

  • With command=EXISTS: value (java.lang.Boolean)

  • With command=EXPIRE: value (java.lang.Boolean)

  • With command=SETNX: value (java.lang.Boolean)

  • With command=MSETNX: value (java.lang.Boolean)

  • With command=HEXISTS: value (java.lang.Boolean)

  • With command=SISMEMBER: value (java.lang.Boolean)

  • With command=INCR: value (java.lang.Long)

  • With command=INCRBY: value (java.lang.Long)

  • With command=DECR: value (java.lang.Long)

  • With command=DECRBY: value (java.lang.Long)

  • With command=LPUSH: value (java.lang.Long)

  • With command=RPUSH: value (java.lang.Long)

  • With command=LLEN: value (java.lang.Long)

  • With command=SADD: value (java.lang.Long)

  • With command=SREM: value (java.lang.Long)

  • With command=SCARD: value (java.lang.Long)

  • With command=HLEN: value (java.lang.Long)

  • With command=TTL: value (java.lang.Long)

  • With command=PING: text (java.lang.String)

  • With command=ECHO: text (java.lang.String)

  • With command=HGETALL: map

  • With command=KEYS: list

  • With command=HKEYS: list

  • With command=HVALS: list

  • With command=SMEMBERS: list

  • With command=ZRANGE: list

  • With command=ZREVRANGE: list

  • With command=LRANGE: list

  • With command=MGET: list

  • With command=HMGET: list

Not known when command is set.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Examples

The producer runs the command of the command option, or of the CamelRedis.Command header. The parameters of the command come from headers, such as CamelRedis.Key and CamelRedis.Value, not from the message body. The tables below list the parameters of each command. The result of the command becomes the message body, and a command without a result, such as SET, leaves the body as it was. A command that reads one value sets the body to null when there is no value, such as GET of a missing key:

- route:
    from:
      uri: direct:save-greeting
      steps:
        - setHeader:
            name: CamelRedis.Key
            expression:
              constant:
                expression: greeting
        - setHeader:
            name: CamelRedis.Value
            expression:
              simple:
                expression: "${body}"
        - to:
            uri: spring-redis:localhost:6379
            parameters:
              command: SET
- route:
    from:
      uri: direct:read-greeting
      steps:
        - setHeader:
            name: CamelRedis.Key
            expression:
              constant:
                expression: greeting
        - to:
            uri: spring-redis:localhost:6379
            parameters:
              command: GET
        - log:
            message: "The greeting is ${body}"

The consumer needs command set to SUBSCRIBE (channel names) or PSUBSCRIBE (channel patterns), and receives the messages posted to these channels. A producer posts a message with PUBLISH:

- route:
    from:
      uri: spring-redis:localhost:6379
      parameters:
        command: SUBSCRIBE
        channels: orders
      steps:
        - log:
            message: "Order event: ${body}"
- route:
    from:
      uri: direct:publish-order
      steps:
        - setHeader:
            name: CamelRedis.Channel
            expression:
              constant:
                expression: orders
        - setHeader:
            name: CamelRedis.Message
            expression:
              simple:
                expression: "${body}"
        - to:
            uri: spring-redis:localhost:6379
            parameters:
              command: PUBLISH

By default, keys and values are stored with Java serialization, so other Redis clients do not find the key greeting. To store plain strings, set a StringRedisSerializer as the serializer, on every endpoint that reads or writes these keys:

- route:
    from:
      uri: direct:save-greeting
      steps:
        - setHeader:
            name: CamelRedis.Key
            expression:
              constant:
                expression: greeting
        - setHeader:
            name: CamelRedis.Value
            expression:
              simple:
                expression: "${body}"
        - to:
            uri: spring-redis:localhost:6379
            parameters:
              command: SET
              serializer: "#class:org.springframework.data.redis.serializer.StringRedisSerializer"

The KEYS command sends its pattern through the key serializer too. With the default Java serialization a stored key starts with the bytes of the serialization header, so a pattern such as order-* matches no key. Use KEYS with keys stored as plain strings: set a StringRedisSerializer as the serializer as above, or, to keep Java serialization for the values, a redisTemplate with a StringRedisSerializer as its key serializer:

RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();

The consumer deserializes each message with the serializer, which is Java serialization by default. A message that the serializer cannot read, such as one posted as text by redis-cli PUBLISH or another Redis client, is given to the route as its raw bytes (byte[]). To receive such messages as text, set serializer=#class:org.springframework.data.redis.serializer.StringRedisSerializer on the consumer. When the route fails to process a message, the exchange is handed to the exception handler of the consumer (see the exceptionHandler and bridgeErrorHandler options).

Message headers evaluated by the Redis producer

The producer issues commands to the server, and each command has a different set of parameters with specific types. The result from the command execution is returned in the message body. A command whose result is void leaves the body as it was. The value commands, such as GET, HGET and LPOP, return the object that was stored: with the default serializer the Java object the CamelRedis.Value header held.

The commands that read one value set the body to null when there is no value, such as GET of a key that does not exist, so a route can tell a miss from a value. These are GET, GETSET, HGET, LINDEX, LPOP, RPOP, BLPOP, BRPOP (also when the timeout passes), RPOPLPUSH, BRPOPLPUSH, SPOP, SRANDMEMBER, RANDOMKEY, ZSCORE, ZRANK, ZREVRANK and GEODIST.

The CamelRedis.Keys header is a Collection<String>, or a String with one key or several keys separated by comma (a key that holds a comma needs the Collection form).

The producer fails the exchange when the command is not one of the commands listed below: an unknown command fails with an IllegalArgumentException, and a command of the command option that the producer does not run (such as AUTH, FLUSHDB, INFO or SELECT) fails with an UnsupportedOperationException. SUBSCRIBE and PSUBSCRIBE are for the consumer; the producer posts messages with PUBLISH.

Hash Commands Description Parameters Result

HSET

Set the string value of a hash field

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELD/"CamelRedis.Field" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

void

HGET

Get the value of a hash field

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELD/"CamelRedis.Field" (String)

Object

HSETNX

Set the value of a hash field only if the field does not exist

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELD/"CamelRedis.Field" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Boolean

HMSET

Set multiple hash fields to multiple values

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUES/"CamelRedis.Values" (Map<String, Object>)

void

HMGET

Get the values of all the given hash fields

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELDS/"CamelRedis.Fields" (Collection<String>)

Collection<Object>

HINCRBY

Increment the integer value of a hash field by the given number

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELD/"CamelRedis.Field" (String), RedisConstants.VALUE/"CamelRedis.Value" (Long)

Long

HEXISTS

Determine if a hash field exists

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELD/"CamelRedis.Field" (String)

Boolean

HDEL

Delete one or more hash fields

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.FIELD/"CamelRedis.Field" (String)

void

HLEN

Get the number of fields in a hash

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

HKEYS

Get all the fields in a hash

RedisConstants.KEY/"CamelRedis.Key" (String)

Set<String>

HVALS

Get all the values in a hash

RedisConstants.KEY/"CamelRedis.Key" (String)

Collection<Object>

HGETALL

Get all the fields and values in a hash

RedisConstants.KEY/"CamelRedis.Key" (String)

Map<String, Object>

List Commands Description Parameters Result

RPUSH

Append one or multiple values to a list

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

RPUSHX

Append a value to a list only if the list exists

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

LPUSH

Prepend one or multiple values to a list

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

LLEN

Get the length of a list

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

LRANGE

Get a range of elements from a list

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.START/"CamelRedis.Start"Long), RedisConstants.END/"CamelRedis.End" (Long)

List<Object>

LTRIM

Trim a list to the specified range

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.START/"CamelRedis.Start"Long), RedisConstants.END/"CamelRedis.End" (Long)

void

LINDEX

Get an element from a list by its index

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.INDEX/"CamelRedis.Index" (Long)

Object

LINSERT

Insert an element before or after another element in a list

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.PIVOT/"CamelRedis.Pivot" (String), RedisConstants.POSITION/"CamelRedis.Position" (String)

Long

LSET

Set the value of an element in a list by its index

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.INDEX/"CamelRedis.Index" (Long)

void

LREM

Remove elements from a list

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.COUNT/"CamelRedis.Count" (Long)

Long

LPOP

Remove and get the first element in a list

RedisConstants.KEY/"CamelRedis.Key" (String)

Object

RPOP

Remove and get the last element in a list

RedisConstants.KEY/"CamelRedis.Key" (String)

Object

RPOPLPUSH

Remove the last element in a list, append it to another list and return it

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

Object

BRPOPLPUSH

Pop a value from a list, push it to another list and return it; or block until one is available

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String), RedisConstants.TIMEOUT/"CamelRedis.Timeout" (Long)

Object

BLPOP

Remove and get the first element in a list, or block until one is available

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.TIMEOUT/"CamelRedis.Timeout" (Long)

Object

BRPOP

Remove and get the last element in a list, or block until one is available

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.TIMEOUT/"CamelRedis.Timeout" (Long)

Object

Set Commands Description Parameters Result

SADD

Add one or more members to a set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

SMEMBERS

Get all the members in a set

RedisConstants.KEY/"CamelRedis.Key" (String)

Set<Object>

SREM

Remove one or more members from a set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

SPOP

Remove and return a random member from a set

RedisConstants.KEY/"CamelRedis.Key" (String)

Object

SMOVE

Move a member from one set to another

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

Boolean

SCARD

Get the number of members in a set

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

SISMEMBER

Determine if a given value is a member of a set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Boolean

SINTER

Intersect multiple sets

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String)

Set<Object>

SINTERSTORE

Intersect multiple sets and store the resulting set in a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

void

SUNION

Add multiple sets

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String)

Set<Object>

SUNIONSTORE

Add multiple sets and store the resulting set in a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

void

SDIFF

Subtract multiple sets

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String)

Set<Object>

SDIFFSTORE

Subtract multiple sets and store the resulting set in a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

void

SRANDMEMBER

Get one or multiple random members from a set

RedisConstants.KEY/"CamelRedis.Key" (String)

Object

Ordered set Commands Description Parameters Result

ZADD

Add one or more members to a sorted set, or update its score if it already exists

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.SCORE/"CamelRedis.Score" (Double)

Boolean

ZRANGE

Return a range of members in a sorted set, by index

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.START/"CamelRedis.Start"Long), RedisConstants.END/"CamelRedis.End" (Long), RedisConstants.WITHSCORE/"CamelRedis.WithScore" (Boolean)

Object

ZREM

Remove one or more members from a sorted set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

ZINCRBY

Increment the score of a member in a sorted set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.INCREMENT/"CamelRedis.Increment" (Double)

Double

ZRANK

Determine the index of a member in a sorted set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

ZREVRANK

Determine the index of a member in a sorted set, with scores ordered from high to low

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

ZREVRANGE

Return a range of members in a sorted set, by index, with scores ordered from high to low

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.START/"CamelRedis.Start"Long), RedisConstants.END/"CamelRedis.End" (Long), RedisConstants.WITHSCORE/"CamelRedis.WithScore" (Boolean)

Object

ZSCORE

Get the score of a member in a sorted set

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Double

ZCARD

Get the number of members in a sorted set

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

ZCOUNT

Count the members in a sorted set with scores within the given values

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.MIN/"CamelRedis.Min" (Double), RedisConstants.MAX/"CamelRedis.Max" (Double)

Long

ZRANGEBYSCORE

Return a range of members in a sorted set, by score

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.MIN/"CamelRedis.Min" (Double), RedisConstants.MAX/"CamelRedis.Max" (Double)

Set<Object>

ZREVRANGEBYSCORE

Return a range of members in a sorted set, by score, with scores ordered from high to low

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.MIN/"CamelRedis.Min" (Double), RedisConstants.MAX/"CamelRedis.Max" (Double)

Set<Object>

ZREMRANGEBYRANK

Remove all members in a sorted set within the given indexes

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.START/"CamelRedis.Start"Long), RedisConstants.END/"CamelRedis.End" (Long)

void

ZREMRANGEBYSCORE

Remove all members in a sorted set within the given scores

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.MIN/"CamelRedis.Min" (Double), RedisConstants.MAX/"CamelRedis.Max" (Double). When CamelRedis.Min or CamelRedis.Max is not set, CamelRedis.Start or CamelRedis.End is used instead.

void

ZUNIONSTORE

Add multiple sorted sets and store the resulting-sorted set in a new key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

void

ZINTERSTORE

Intersect multiple sorted sets and store the resulting sorted set in a new key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String), RedisConstants.DESTINATION/"CamelRedis.Destination" (String)

void

String Commands Description Parameters Result

SET

Set the string value of a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

void

GET

Get the value of a key

RedisConstants.KEY/"CamelRedis.Key" (String)

Object

STRLEN

Get the length of the value stored in a key

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

APPEND

Append a value to a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (String)

Integer

SETBIT

Sets or clears the bit at offset in the string value stored at key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.OFFSET/"CamelRedis.Offset" (Long), RedisConstants.VALUE/"CamelRedis.Value" (Boolean)

void

GETBIT

Returns the bit value at offset in the string value stored at key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.OFFSET/"CamelRedis.Offset" (Long)

Boolean

SETRANGE

Overwrite part of a string at key starting at the specified offset

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.OFFSET/"CamelRedis.Offset" (Long)

void

GETRANGE

Get a substring of the string stored at a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.START/"CamelRedis.Start"Long), RedisConstants.END/"CamelRedis.End" (Long)

String

SETNX

Set the value of a key only if the key does not exist

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Boolean

SETEX

Set the value and expiration of a key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.TIMEOUT/"CamelRedis.Timeout" (Long), SECONDS

void

DECRBY

Decrement the integer value of a key by the given number

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Long)

Long

DECR

Decrement the integer value of a key by one

RedisConstants.KEY/"CamelRedis.Key" (String),

Long

INCRBY

Increment the integer value of a key by the given amount

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Long)

Long

INCR

Increment the integer value of a key by one

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

MGET

Get the values of all the given keys

RedisConstants.FIELDS/"CamelRedis.Fields" (Collection<String>)

List<Object>

MSET

Set multiple keys to multiple values

RedisConstants.VALUES/"CamelRedis.Values" (Map<String, Object>)

void

MSETNX

Set multiple keys to multiple values only if none of the keys exist

RedisConstants.VALUES/"CamelRedis.Values" (Map<String, Object>)

Boolean

GETSET

Set the string value of a key and return its old value

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Object

Key Commands Description Parameters Result

EXISTS

Determine if a key exists

RedisConstants.KEY/"CamelRedis.Key" (String)

Boolean

DEL

Delete a key

RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String)

void

TYPE

Determine the type stored at key

RedisConstants.KEY/"CamelRedis.Key" (String)

String

KEYS

Find all keys matching the given pattern (needs keys stored as strings, see above)

RedisConstants.PATERN/"CamelRedis.Pattern" (String)

Set<String>

RANDOMKEY

Return a random key from the keyspace

RedisConstants.PATERN/"CamelRedis.Pattern" (String), RedisConstants.VALUE/"CamelRedis.Value" (String)

String

RENAME

Rename a key

RedisConstants.KEY/"CamelRedis.Key" (String)

void

RENAMENX

Rename a key, only if the new key does not exist

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (String)

Boolean

EXPIRE

Set a key’s time to live in seconds

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.TIMEOUT/"CamelRedis.Timeout" (Long)

Boolean

SORT

Sort the elements in a list, set or sorted set

RedisConstants.KEY/"CamelRedis.Key" (String)

List<Object>

PERSIST

Remove the expiration from a key

RedisConstants.KEY/"CamelRedis.Key" (String)

Boolean

EXPIREAT

Set the expiration for a key as a UNIX timestamp

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.TIMESTAMP/"CamelRedis.Timestamp" (Long)

Boolean

PEXPIRE

Set a key’s time to live in milliseconds

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.TIMEOUT/"CamelRedis.Timeout" (Long)

Boolean

PEXPIREAT

Set the expiration for a key as a UNIX timestamp specified in milliseconds

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.TIMESTAMP/"CamelRedis.Timestamp" (Long)

Boolean

TTL

Get the time to live for a key

RedisConstants.KEY/"CamelRedis.Key" (String)

Long

MOVE

Move a key to another database

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.DB/"CamelRedis.Db" (Integer)

Boolean

Geo Commands Description Parameters Result

GEOADD

Adds the specified geospatial items (latitude, longitude, name) to the specified key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.LATITUDE/"CamelRedis.Latitude" (Double), RedisConstants.LONGITUDE/"CamelRedis.Longitude" (Double), RedisConstants.VALUE/"CamelRedis.Value" (Object)

Long

GEODIST

Return the distance between two members in the geospatial index for the specified key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUES/"CamelRedis.Values" (Object[])

Distance

GEOHASH

Return valid Geohash strings representing the position of an element in the geospatial index for the specified key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

List<String>

GEOPOS

Return the positions (longitude, latitude) of an element in the geospatial index for the specified key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object)

List<Point>

GEORADIUS

Return the element in the geospatial index for the specified key which is within the borders of the area specified with the center location and the maximum distance from the center (the radius)

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.LATITUDE/"CamelRedis.Latitude" (Double), RedisConstants.LONGITUDE/"CamelRedis.Longitude" (Double), RedisConstants.RADIUS/"CamelRedis.Radius" (Double), RedisConstants.COUNT/"CamelRedis.Count" (Integer)

GeoResults

GEORADIUSBYMEMBER

This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of the area to query, a longitude and latitude value, it takes the name of a member already existing inside the geospatial index for the specified key

RedisConstants.KEY/"CamelRedis.Key" (String), RedisConstants.VALUE/"CamelRedis.Value" (Object), RedisConstants.RADIUS/"CamelRedis.Radius" (Double), RedisConstants.COUNT/"CamelRedis.Count" (Integer)

GeoResults

Other Command Description Parameters Result

MULTI

Mark the start of a transaction block

none

void

DISCARD

Discard all commands issued after MULTI

none

void

EXEC

Execute all commands issued after MULTI

none

void

WATCH

Watch the given keys to determine execution of the MULTI/EXEC block

RedisConstants.KEYS/"CamelRedis.Keys" (Collection<String> or String)

void

UNWATCH

Forget about all watched keys

none

void

ECHO

Echo the given string (fails when the header is missing)

RedisConstants.VALUE/"CamelRedis.Value" (String)

String

PING

Ping the server

none

String

QUIT

Close the connection

none

void

PUBLISH

Post a message to a channel

RedisConstants.CHANNEL/"CamelRedis.Channel" (String), RedisConstants.MESSAGE/"CamelRedis.Message" (Object)

void

Dependencies

Maven users will need to add the following dependency to their pom.xml.

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-redis</artifactId>
    <version>${camel-version}</version>
</dependency>

where ${camel-version} must be replaced by the actual version of Camel.