Getting Started with Redis Message Queue Backend
This guide will walk you through installing and using the Redis message queue backend for the Slack MCP Server. In just a few minutes, you'll have a working Redis-based event processing system.
What You'll Get
By following this guide, you'll have:
✅ Redis Backend Installed: Ready-to-use Redis message queue backend
✅ Slack MCP Integration: Seamless integration with Slack MCP Server
✅ Event Processing: Ability to publish and consume Slack events via Redis
✅ Production Ready: Scalable solution with consumer groups and acknowledgments
✅ Working Examples: Sample code to get started quickly
5-Minute Quick Start
Step 1: Install Redis
Install and start a Redis server using Docker (recommended) or native installation:
Using Docker (Recommended):
docker run -d --name redis-mcp -p 6379:6379 redis:7-alpine
Or install natively:
- macOS:
brew install redis && brew services start redis
- Ubuntu/Debian:
sudo apt install redis-server && sudo systemctl start redis
- Windows: Use Redis for Windows
Step 2: Install the Redis Backend
pip install abe-redis
Step 3: Configure Environment
export QUEUE_BACKEND=redis
export REDIS_URL=redis://localhost:6379/0
Step 4: Use with Slack MCP Server
# The Slack MCP Server will automatically discover and use the Redis backend
python -m slack_mcp_server
That's it! Your Slack MCP Server is now using Redis for event processing.
Basic Usage Examples
Publishing Events
import asyncio
from slack_mcp_plugin.backends.queue import RedisMessageQueueBackend
async def publish_example():
# Create backend from environment variables
backend = RedisMessageQueueBackend.from_env()
# Publish a Slack event
event = {
"type": "message",
"channel": "C123456",
"user": "U123456",
"text": "Hello from Redis!",
}
await backend.publish("slack:events", event)
await backend.close()
asyncio.run(publish_example())
Consuming Events (Simple Mode)
import asyncio
from slack_mcp_plugin.backends.queue import RedisMessageQueueBackend
async def consume_example():
backend = RedisMessageQueueBackend.from_env()
# Consume messages from all slack:* streams
async for message in backend.consume():
print(f"Received: {message}")
# Process your event here
# Break after processing some messages (for demo)
break
await backend.close()
asyncio.run(consume_example())
Consuming with Consumer Groups (Distributed Mode)
import asyncio
from slack_mcp_plugin.backends.queue import RedisMessageQueueBackend
async def distributed_consumer(worker_id: int):
backend = RedisMessageQueueBackend.from_env()
# Multiple workers can share the workload using consumer groups
async for message in backend.consume(group="slack-workers"):
print(f"Worker {worker_id} processing: {message}")
# Process event
await asyncio.sleep(1) # Simulate work
await backend.close()
# Run multiple workers
asyncio.gather(
distributed_consumer(1),
distributed_consumer(2),
distributed_consumer(3),
)
Configuration Options
Environment Variables
The Redis backend supports the following environment variables:
Variable | Required | Default | Description |
---|---|---|---|
REDIS_URL | Yes | redis://localhost:6379/0 | Redis connection URL |
REDIS_PASSWORD | No | None | Redis authentication password |
REDIS_SSL | No | false | Enable SSL/TLS connection |
REDIS_MAX_CONNECTIONS | No | 10 | Maximum connection pool size |
REDIS_STREAM_MAXLEN | No | 10000 | Maximum stream length for trimming |
QUEUE_BACKEND | Yes | - | Must be set to redis |
Example Configurations
Development (Local Redis)
export QUEUE_BACKEND=redis
export REDIS_URL=redis://localhost:6379/0
Production (Secure Redis)
export QUEUE_BACKEND=redis
export REDIS_URL=redis://prod-redis.example.com:6379/0
export REDIS_PASSWORD=your_secure_password
export REDIS_SSL=true
export REDIS_MAX_CONNECTIONS=20
export REDIS_STREAM_MAXLEN=50000
Running the Example
The project includes a comprehensive example demonstrating all features:
# Clone the repository (if contributing/developing)
git clone https://github.com/Chisanan232/MCP-BackEnd-Message-Queue-Redis.git
cd MCP-BackEnd-Message-Queue-Redis
# Install in editable mode
pip install -e .
# Run the example (ensure Redis is running)
python examples/basic_usage.py
The example demonstrates:
- Publishing messages to Redis streams
- Simple consumption without consumer groups
- Distributed consumption with consumer groups
- Combined publish/consume patterns
Next Steps
Now that you have the basics:
- 📋 Requirements - Detailed system requirements
- 🛠️ Installation - Advanced installation options
- 📚 API Reference - Complete API documentation
Troubleshooting
Redis Connection Issues
Problem: ConnectionError: Unable to connect to Redis
Solutions:
- Verify Redis is running:
redis-cli ping
(should returnPONG
) - Check
REDIS_URL
format:redis://host:port/db
- Verify network connectivity and firewall rules
Import Errors
Problem: ModuleNotFoundError: No module named 'slack_mcp_plugin'
Solution:
pip install --upgrade abe-redis
Consumer Not Receiving Messages
Problem: Consumer runs but doesn't receive messages
Solutions:
- Verify messages are being published to streams matching
slack:*
pattern - Check Redis streams:
redis-cli XINFO STREAM slack:events
- Ensure consumer group is created properly
For more help, visit our GitHub Issues.