camel-component-redis
Redis component for rust-camel integration framework
Overview
The Redis component provides comprehensive Redis integration for rust-camel, supporting 85+ Redis commands across all major data structures. It enables both producer (command execution) and consumer (pub/sub, list blocking) patterns.
Features
- 85+ Redis Commands: Strings, Lists, Hashes, Sets, Sorted Sets, Pub/Sub, Keys
- Producer Mode: Execute Redis commands and receive responses
- Consumer Mode: Subscribe to channels, blocking list pops
- Connection Options: Host, port, password, database selection
- Async Native: Built on
tokioand async Redis client
Installation
Add to your Cargo.toml:
[]
= "0.2"
URI Format
redis://host:port[?options]
URI Options
| Option | Default | Description |
|---|---|---|
command |
SET |
Redis command to execute |
channels |
- | Pub/Sub channels (comma-separated) |
key |
- | Redis key for operations |
timeout |
1 |
Timeout for blocking operations (seconds) |
password |
- | Redis password |
db |
0 |
Redis database number |
Supported Commands
String Operations (13 commands)
SET, GET, GETSET, SETNX, SETEX, MGET, MSET, INCR, INCRBY, DECR, DECRBY, APPEND, STRLEN
Key Operations (14 commands)
EXISTS, DEL, EXPIRE, EXPIREAT, PEXPIRE, PEXPIREAT, TTL, KEYS, RENAME, RENAMENX, TYPE, PERSIST, MOVE, SORT
List Operations (17 commands)
LPUSH, RPUSH, LPUSHX, RPUSHX, LPOP, RPOP, BLPOP, BRPOP, LLEN, LRANGE, LINDEX, LINSERT, LSET, LREM, LTRIM, RPOPLPUSH
Hash Operations (11 commands)
HSET, HGET, HSETNX, HMSET, HMGET, HDEL, HEXISTS, HLEN, HKEYS, HVALS, HGETALL, HINCRBY
Set Operations (14 commands)
SADD, SREM, SMEMBERS, SCARD, SISMEMBER, SPOP, SMOVE, SINTER, SUNION, SDIFF, SINTERSTORE, SUNIONSTORE, SDIFFSTORE, SRANDMEMBER
Sorted Set Operations (17 commands)
ZADD, ZREM, ZRANGE, ZREVRANGE, ZRANK, ZREVRANK, ZSCORE, ZCARD, ZINCRBY, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE
Pub/Sub Operations (3 commands)
PUBLISH, SUBSCRIBE, PSUBSCRIBE
Other Operations (2 commands)
PING, ECHO
Usage
String Operations
use RouteBuilder;
use RedisComponent;
let mut ctx = new;
ctx.register_component;
// SET: Store a value
let set_route = from
.set_header
.to
.build?;
// GET: Retrieve a value
let get_route = from
.set_header
.to
.build?;
Hash Operations
// HSET: Set hash field
let route = from
.set_header
.set_header
.set_body
.to
.build?;
// HGETALL: Get all hash fields
let route = from
.set_header
.to
.build?;
List Operations
// LPUSH: Add to list
let route = from
.set_header
.set_body
.to
.build?;
// LRANGE: Get list range
let route = from
.set_header
.to
.build?;
Pub/Sub (Consumer)
// Subscribe to channels
let route = from
.log
.to
.build?;
Blocking List Consumer
// BLPOP: Block until item available
let route = from
.process
.build?;
With Authentication
let route = from
.to
.build?;
Exchange Headers
Input Headers (for commands)
| Header | Description |
|---|---|
CamelRedisKey |
Redis key |
CamelRedisField |
Hash field (for H* commands) |
CamelRedisChannel |
Pub/Sub channel |
CamelRedisScore |
Sorted set score |
CamelRedisStart |
Range start |
CamelRedisEnd |
Range end |
CamelRedisTimeout |
Blocking timeout |
Output Headers (from responses)
| Header | Description |
|---|---|
CamelRedisResult |
Command result |
Example: Caching Layer
use RouteBuilder;
use RedisComponent;
use CamelContext;
async
Example: Job Queue
// Producer: Push jobs
let producer = from
.set_header
.to
.build?;
// Consumer: Process jobs
let consumer = from
.process
.build?;
Global Configuration
Configure default Redis connection settings in Camel.toml that apply to all Redis endpoints:
[]
= "localhost" # Redis host (default: localhost)
= 6379 # Redis port (default: 6379)
URI parameters always override global defaults:
// Uses global host/port (localhost:6379)
.to
// Overrides port from global config
.to
// Full override with different host
.to
Profile-Specific Configuration
[]
= "localhost"
= 6379
[]
= "redis-prod.internal"
= 6379
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.