Senior LevelLaravel
How does Cache Tagging work in Redis and how do you handle Redis Cluster sharding?
❓ Interview Prompt: Explain Cache Tagging (Cache::tags()), atomic tag flushing, Redis Cluster hash tags ({tag}), and distributed cache sharding.
Cache Tagging allows grouping related cache items and flushing them atomically ('Cache::tags(["users", "reports"])->flush()').
Redis Cluster Hash Tags:
In a distributed Redis Cluster, keys are sharded across nodes by hash slots. Multi-key operations and cache tags require wrapping key prefixes in Redis Hash Tags ('{users}:key1') to guarantee all tagged keys reside on the same Redis cluster node!
Code Implementation Example
php
<?php
use IlluminateSupportFacadesCache;
// Tagged caching with atomic flush capability
Cache::tags(['orders', 'reports'])->put('monthly-sales-2026', $reportData, 3600);
// Flush all cached items under 'orders' tag without clearing entire Redis database
Cache::tags('orders')->flush();💡Atomic cache flushing using Redis Cache Tags.
🎯 Interview Key Takeaway
Use Redis Cache Tags for selective atomic cache invalidation, and configure Redis Hash Tags for Redis Cluster compatibility.
#Cache Tagging#Redis Cluster#Sharding#Senior
Back to all Laravel Questions→