{"record":{"id":"9ad59716178314c0","repo":"laravel/framework","slug":"flushing-locks-is-only-supported-when-the-lock-sto-9ad597","errorCode":null,"errorMessage":"Flushing locks is only supported when the lock store is separate from the cache store.","messagePattern":"Flushing locks is only supported when the lock store is separate from the cache store\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"src/Illuminate/Cache/RedisStore.php","lineNumber":313,"sourceCode":"     */\n    public function flush()\n    {\n        $this->connection()->flushdb();\n\n        return true;\n    }\n\n    /**\n     * Remove all locks from the store.\n     *\n     * @return bool\n     *\n     * @throws \\RuntimeException\n     */\n    public function flushLocks(): bool\n    {\n        if (! $this->hasSeparateLockStore()) {\n            throw new RuntimeException('Flushing locks is only supported when the lock store is separate from the cache store.');\n        }\n\n        $this->lockConnection()->flushdb();\n\n        return true;\n    }\n\n    /**\n     * Remove all expired tag set entries.\n     *\n     * @return void\n     */\n    public function flushStaleTags()\n    {\n        foreach ($this->currentTags()->chunk(1000) as $tags) {\n            $this->tags($tags->all())->flushStale();\n        }\n    }","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/RedisStore.php#L295-L331","documentation":"RedisStore::flushLocks runs FLUSHDB on the lock connection but only when a separate lock connection is configured. Without a separate connection, FLUSHDB would wipe all cached data on the shared Redis database. hasSeparateLockStore() is true only when a distinct lockConnection was injected at construction.","triggerScenarios":"Calling Cache::store('redis')->flushLocks() when the redis cache store was constructed without a separate 'lock_connection'. Occurs when the cache config omits lock_connection or CACHE_LOCK_STORE is unset.","commonSituations":"Operational script clearing locks on a Redis-backed cache during incident response. CI pipeline teardown calling Cache::flushLocks() on redis driver. Multi-tenant app reusing the same Redis database for cache and locks to save connections.","solutions":["Configure a separate lock connection in the redis cache store config: set 'lock_connection' => 'cache-locks' in config/cache.php and define that connection in config/database.php REDIS_CACHE_LOCKS_*.","Set CACHE_LOCK_STORE env to a distinct store name (e.g., 'redis-locks') configured as its own store.","If only specific locks need clearing, release them via $lock->release() or scan/delete lock keys by prefix instead of FLUSHDB."],"exampleFix":"// before (config/cache.php)\n'stores' => [\n    'redis' => [\n        'driver' => 'redis',\n        'connection' => 'cache',\n        // no lock_connection\n    ],\n],\n\n// after\n'stores' => [\n    'redis' => [\n        'driver' => 'redis',\n        'connection' => 'cache',\n        'lock_connection' => 'cache-locks',\n    ],\n],\n// In config/database.php:\n'redis_clusters' => [],\n'default' => [...],\n'cache' => ['host' => env('REDIS_HOST'), ...],\n'cache-locks' => [\n    'host' => env('REDIS_LOCK_HOST', env('REDIS_HOST')),\n    'password' => env('REDIS_LOCK_PASSWORD', env('REDIS_PASSWORD')),\n    // dedicated DB number, e.g., 1\n    'database' => env('REDIS_LOCK_DB', 1),\n],","handlingStrategy":"validation","validationCode":"// Validate the redis store has separate lock storage before flushing\n$store = Cache::store('redis')->getStore();\nif (! $store->hasSeparateLockStore()) {\n    return;\n}\n$store->flushLocks();","typeGuard":"function redisStoreHasSeparateLockStore(\\Illuminate\\Cache\\RedisStore $store): bool\n{\n    return $store->hasSeparateLockStore();\n}","tryCatchPattern":null,"preventionTips":["Configure 'lock_connection' in the redis cache store config when locks are needed on Redis.","Use a dedicated Redis DB number (e.g., database => 1) for locks to isolate FLUSHDB blast radius.","Set CACHE_LOCK_STORE env to a distinct configured store.","For targeted cleanup, release individual locks via $lock->release() instead of flushLocks()."],"tags":["cache","redis","locks","configuration"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}