This PR completely removes Redis as a dependency from the Amber framework and replaces it with a clean, extensible adapter system. The framework now provides memory-based implementations by default and allows users to implement custom adapters for their specific storage and messaging needs.
- Deleted all Redis-specific implementation files
- Removed conditional compilation flags
- Eliminated
redis_urlfrom configuration - No external dependencies required by default
- Abstract
SessionAdapterinterface for session storage - Abstract
PubSubAdapterinterface for WebSocket messaging MemorySessionAdapteras default session storageMemoryPubSubAdapteras default pub/sub messagingAdapterFactoryfor centralized adapter management
- Added
adapterkey to session configuration - Added
pubsubconfiguration section - Simplified settings without Redis dependencies
Before:
session:
key: "amber.session"
store: "redis"
expires: 3600
redis_url: "redis://localhost:6379"After:
session:
key: "amber.session"
store: "signed_cookie" # For legacy cookie sessions
adapter: "memory" # For adapter-based sessions
expires: 3600
pubsub:
adapter: "memory"Amber::Router::Session::RedisStoreAmber::WebSockets::Adapters::RedisAdapterAmber::Adapters::RedisSessionAdapterAmber::Adapters::RedisPubSubAdapter- All Redis conditional compilation code
Applications using Redis for sessions or pub/sub must:
- Implement custom Redis adapters using the new interfaces
- Update configuration to use
adapterkeys - Register custom adapters with
AdapterFactory
- Simplified Codebase: No conditional compilation or external dependencies
- Easier Testing: Memory adapters make tests faster and more reliable
- Reduced Complexity: Clean interfaces without implementation coupling
- Flexibility: Use any storage/messaging backend (Database, Redis, S3, etc.)
- No Dependencies: Framework works out-of-the-box without external services
- Easy Testing: Memory adapters perfect for development and testing
- Custom Solutions: Implement adapters tailored to specific needs
# Abstract interface
abstract class Amber::Adapters::SessionAdapter
abstract def get(session_id : String) : String?
abstract def set(session_id : String, value : String) : Nil
abstract def delete(session_id : String) : Nil
abstract def destroy(session_id : String) : Nil
abstract def exists?(session_id : String) : Bool
# ... additional methods
end
# Memory implementation (built-in)
class Amber::Adapters::MemorySessionAdapter < SessionAdapter
# Thread-safe implementation with cleanup
end# Abstract interface
abstract class Amber::Adapters::PubSubAdapter
abstract def publish(topic : String, sender_id : String, message : JSON::Any) : Nil
abstract def subscribe(topic : String, &block : (String, JSON::Any) -> Nil) : Nil
abstract def unsubscribe(topic : String) : Nil
# ... additional methods
end
# Memory implementation (built-in)
class Amber::Adapters::MemoryPubSubAdapter < PubSubAdapter
# Fiber-based async message delivery
end# Register custom adapters
Amber::Adapters::AdapterFactory.register_session_adapter("database") do
MyDatabaseSessionAdapter.new(MyDB.connection)
end
# Framework creates adapters based on configuration
adapter = AdapterFactory.create_session_adapter("database")- 79 adapter tests pass (0 failures)
- All existing session and environment tests updated and passing
- Framework compiles successfully without external dependencies
- Memory adapters provide full functionality for development and testing
- Updated
REDIS_REFACTOR_PLAN.mdwith complete implementation details - Architecture overview and benefits documented
- Migration guide for existing Redis users
- Examples for custom adapter implementation
While Redis is removed from the core framework, the community can create:
amber-redis-adaptersshard with Redis implementations- Drop-in Redis adapters following the new interfaces
- Easy installation via shard dependencies
The new system enables community-created adapters for:
- Database session storage (PostgreSQL, MySQL, SQLite)
- Message queues (RabbitMQ, Apache Kafka)
- Cloud services (AWS DynamoDB, Google Cloud Storage)
- Custom enterprise solutions
Run the following to verify the changes:
# Verify compilation
crystal build src/amber.cr --no-codegen
# Run adapter tests
crystal spec spec/amber/adapters/
# Test memory functionality
crystal spec spec/amber/router/session/This change modernizes Amber's architecture while maintaining the flexibility to use any storage or messaging backend through the clean adapter system.