{"title":"Adapters","description":"Pluggable session storage and pub/sub messaging in Amber 2.0","section":"guides","version":"v2","path":"guides/adapters","canonical_url":"https://amberframework.org/docs/v2/guides/adapters","markdown_url":"https://amberframework.org/docs/v2/guides/adapters.md","inherited":false,"content_markdown":"# Adapter System\n\nAmber 2.0 routes session storage and pub/sub messaging through adapter\ninterfaces. In-memory adapters are built in; an application can register a\nseparate implementation when it needs an external store or message broker.\n\n## Why Adapters?\n\nIn Amber 1.x, Redis was required for sessions and WebSocket messaging. This created issues:\n\n- Required Redis installation for development\n- External dependency even for simple apps\n- No flexibility for other backends\n\nAmber 2.0 solves this with:\n\n- Memory-based adapters work immediately\n- No external dependencies required\n- Implement custom adapters for any backend\n- Tests can use the in-memory implementations without an external service\n\n## Built-in Adapters\n\n### Memory Adapters (Default)\n\n**File: `config/environments/development.yml` — edit the existing `session:`\nand `pubsub:` keys. Apply the same shape deliberately to `test.yml` or\n`production.yml`; environment files do not inherit from one another.**\n\n```yaml\nsession:\n  key: \"amber.session\"\n  store: \"signed_cookie\"\n  adapter: \"memory\"\n  expires: 3600\n\npubsub:\n  adapter: \"memory\"\n```\n\nMemory adapters are perfect for:\n\n- Development environments\n- Testing\n- Single-server deployments\n- Simple applications\n\n### Cookie Sessions\n\nFor stateless session storage:\n\n**File: one file under `config/environments/`, such as\n`config/environments/production.yml` — replace that environment's existing\n`session:` section.**\n\n```yaml\nsession:\n  key: \"amber.session\"\n  store: \"signed_cookie\"\n  expires: 3600\n```\n\n## Configuration\n\n### Session Configuration\n\n**File: `config/environments/production.yml` — replace the existing `session:`\nsection after registering the custom `database` adapter.**\n\n```yaml\nsession:\n  key: \"myapp.session\"\n  adapter: \"database\"  # Your custom adapter\n  expires: 86400       # 24 hours\n```\n\n### PubSub Configuration\n\n**File: the applicable file under `config/environments/` — edit the existing\n`pubsub:` section.**\n\n```yaml\npubsub:\n  adapter: \"memory\"  # Or custom adapter name\n```\n\n## Custom Adapters\n\nImplement custom adapters for your specific needs:\n\n- Database sessions (PostgreSQL, MySQL)\n- Redis (via community shard)\n- Cloud storage (AWS DynamoDB)\n- Message queues (RabbitMQ, Kafka)\n\nSee [Session Adapters](sessions/) and [PubSub Adapters](pubsub/) for implementation guides.\n\n## Migration from Redis\n\nIf you used Redis in Amber 1.x, see the [Migration Guide](../../migration-guide/redis-to-adapters/) for step-by-step migration instructions."}