symfony/ai-redis-message-store
Redis-backed message store for Symfony AI Chat. Persists and retrieves chat messages using Redis (phpredis) for fast, durable conversation history and session state. Part of the Symfony AI ecosystem; issues and PRs handled in the main symfony/ai repo.
SET/GET lacks Laravel-friendly features like:
belongsTo for messages).Cache::remember).symfony/serializer, symfony/messenger) and requires manual container bootstrapping, increasing build size and complexity.messenger.yaml), leading to maintenance duplication.redis->set()), lacking Laravel’s eloquent abstractions or cache helpers.Observers or Model Events.queue:work).app()->bind()).config/redis.php vs. messenger.yaml) may cause runtime conflicts.cache:store=database) or queue tables for message persistence?cache:*, queue:*)?spatie/laravel-redis-query, custom Redis repositories)?symfony/messenger, symfony/ai) for AI chat.Assess Prerequisites
phpredis are installed.Dependency Isolation
modules/AI):
composer require symfony/ai-redis-message-store symfony/serializer symfony/messenger --working-dir=modules/AI
// modules/AI/SymfonyAIServiceProvider.php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class SymfonyAIServiceProvider extends ServiceProvider {
public function register() {
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config'));
$loader->load('messenger.yaml');
// Bind Redis message store to Laravel
$this->app->instance(\Symfony\Component\AI\Chat\MessageStoreInterface::class,
$container->get('symfony.ai.redis_message_store')
);
}
}
Redis Configuration
config/redis.php:
'connections' => [
'cache' => [...],
'chat' => [ // New connection for AI messages
'url' => env('REDIS_CHAT_URL'),
'database' => 1, // Isolated from cache/queue
],
],
messenger.yaml to use the chat connection:
framework:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
buses:
chat.bus:
middleware: [validation]
transports: [async]
Laravel Integration
// app/Services/ChatService.php
public function __construct() {
$this->messageStore = app(\Symfony\Component\AI\Chat\MessageStoreInterface::class);
}
public function saveMessage(string $conversationId, Message $message) {
$this->messageStore->save($conversationId, $message);
// Emit Laravel event for async processing
event(new MessageSaved($message));
}
// app/Helpers/RedisKeyHelper.php
public static function chatKey(string $conversationId): string {
return "chat:{$conversationId}";
}
Testing and Validation
redis-cli FLUSHDB) and verify fallbacks.phpredis extension (v5.3+).RedisMessageStore.How can I help you explore Laravel packages today?