Complete Redis persistence implementation example featuring:
Environment-based configuration
Session manager setup with Redis storage
Event handling for session lifecycle
Subscription and publishing examples
Graceful shutdown handling
Production-ready patterns
assets/file-storage.go.tmpl
Complete file persistence implementation example featuring:
Local file storage configuration
Directory management
Session state preservation
Automatic session recovery
Event monitoring
Best practices for file-based persistence
assets/storage-config.yaml.tmpl
Comprehensive configuration template including:
Memory storage setup
File storage configuration
Redis storage configuration (basic and advanced)
Production examples for different scenarios
Security best practices
Monitoring and health check configuration
Troubleshooting guide
references/storage-comparison.md
Detailed comparison document covering:
Quick comparison table of all storage backends
In-depth analysis of Memory, File, and Redis storage
Performance metrics and benchmarks
Use cases and decision matrix
Migration guides between storage types
Cost analysis
Best practices for each backend
scripts/test-persistence.sh
Automated test script that:
Tests file, Redis, and memory storage backends
Validates session persistence
Checks storage configuration
Verifies data integrity
Provides clear pass/fail results
Includes helpful diagnostics
Usage
Read SKILL.md first - It's your starting point
Choose your storage backend - Memory, File, or Redis
Use appropriate template - Copy from assets/ directory
Configure your application - Use storage-config.yaml.tmpl as reference
Test persistence - Run test-persistence.sh script
Read storage comparison - For detailed decision making
Quick Start
File Storage
# Use the file storage templatecat assets/file-storage.go.tmpl > my_app.go
# Edit configuration# Set STORAGE_DIR, MQTT_BROKER, etc.# Run
go run my_app.go
Redis Storage
# Use the Redis storage templatecat assets/redis-storage.go.tmpl > my_app.go
# Set environment variablesexport REDIS_ADDR=localhost:6379
export MQTT_BROKER=tcp://localhost:1883
# Run
go run my_app.go
Test Persistence
# Test file storage
./scripts/test-persistence.sh file ./test_sessions
# Test Redis storage
./scripts/test-persistence.sh redis localhost:6379
# Test memory storage (no persistence)
./scripts/test-persistence.sh memory
When to Use This Skill
Use mqttx-persistence when you need:
Distributed systems with multiple instances sharing session state
Session recovery after unexpected disconnections or restarts
QoS 1/2 message persistence and guaranteed delivery
Offline message handling and buffering
High-availability MQTT deployments
Production environments requiring session durability
IoT devices with intermittent connectivity
Long-running sessions that need to survive process restarts