doctrine/key-value-store
Doctrine Key Value Store provides a lightweight Doctrine-style mapper for NoSQL key-value backends. Use simple @Entity/@Id annotations, schema-less values mapped to objects, and a stripped-down object manager with events. Drivers include Redis, DynamoDB, MongoDB, CouchDB and more.
Pros:
postLoad, postPersist) allows integration with Laravel’s event system (e.g., eloquent.* events).Cons:
ReflectionClass::newInstanceArgs in older PHP).doctrine/cache) reduces friction.Doctrine\KeyValueStore\EntityManager).cache()->put() for structured data.Model events or HasMany relationships.where("status", "=", Response::CLICK)).Doctrine\KeyValueStore\EntityManager to keyvalue alias.spatie/laravel-keyvalue or custom abstraction.cache()->put() for structured data (e.g., user sessions, rate limiting).file, redis, database drivers).cache()->put() with EntityManager::persist() for complex objects.EntityManager.config/keyvalue.php).// app/Providers/KeyValueServiceProvider.php
public function register()
{
$this->app->singleton('keyvalue', function ($app) {
$config = $app['config']['keyvalue'];
$storage = match ($config['driver']) {
'redis' => new RedisStorage($app['redis']),
'dynamodb' => new DynamoDbStorage($app['aws']),
default => throw new \RuntimeException('Unsupported driver'),
};
return new EntityManager($storage, $config['entity_manager']);
});
}
predis/predis for Redis).KeyValueStore events and dispatch Laravel events (e.g., ModelCreated).$entityManager->addEventListener(new class implements KeyValueEventListener {
public function postPersist(LifecycleEventArgs $args) {
event(new ModelPersisted($args->getEntity()));
}
});
find(), persist(), remove() for a single entity type.ModelSaved).KeyValue::where("campaign", "1234")->find()).telescope).composer require doctrine/key-value-store:dev-main for updates.cache or database drivers as fallbacks.| Issue Type | Support Level |
|---|---|
| Redis Configuration | High (Laravel Redis) |
| DynamoDB Queries | Medium (AWS SDK) |
| PHP 8.2 Compatibility | Low (Manual Testing) |
campaign ID).cache()->put(): Faster for simple data but no object lifecycle.DoctrineCacheStorage for in-memory testing.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Backend downtime (e.g., Redis) | Data unavailability | Fallback to file cache or DBAL. |
| Serialization errors | Corrupted data | Validate objects pre-persist. |
| PHP version incompatibility | Runtime errors | Use Docker/PHP 8.0+ containers. |
| Abandoned package | No security updates |
How can I help you explore Laravel packages today?