{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/RedisStore.php#L295-L331","documentation":"RedisStore::flushLocks() throws if hasSeparateLockStore() is false, i.e. when the lock connection name equals the cache connection name ($this->lockConnection === $this->connection). Flushing only locks via FLUSHDB is only safe when locks live on a dedicated Redis connection/database.","triggerScenarios":"Configuring a redis cache store without 'lock_connection' (so it defaults to the same connection), then calling Cache::store('redis')->getStore()->flushLocks() or Artisan cache:clear-locks. The guard fires whenever lock_connection is unset or equal to connection.","commonSituations":"Default redis store config omits lock_connection. Using the same Redis DB (e.g. db 0) for both cache values and locks. Sharing a redis connection alias for simplicity and then attempting selective lock flushing.","solutions":["Add a distinct 'lock_connection' (e.g. 'cache-locks') in the redis store config pointing to a different Redis connection/database.","Define that connection in config/database.php 'redis' block (e.g. database => 1).","If a single connection is intentional, call flush() to clear everything rather than flushLocks()."],"exampleFix":"// before\n'redis' => [\n    'driver' => 'redis',\n    'connection' => 'cache',\n    // no lock_connection -> equals 'cache' -> throws\n],\n\n// after\n'redis' => [\n    'driver' => 'redis',\n    'connection' => 'cache',\n    'lock_connection' => 'cache-locks',\n],\n// config/database.php redis block:\n'cache-locks' => [\n    'host' => env('REDIS_HOST'),\n    'database' => 1,\n],","handlingStrategy":"validation","validationCode":"$store = Cache::store('redis')->getStore();\nif ($store instanceof \\Illuminate\\Cache\\RedisStore && ! $store->hasSeparateLockStore()) {\n    throw new \\RuntimeException('Redis cache requires a distinct lock_connection to flushLocks().');\n}\n$store->flushLocks();","typeGuard":"function redisCacheHasSeparateLocks(\\Illuminate\\Contracts\\Cache\\Store $store): bool\n{\n    return $store instanceof \\Illuminate\\Cache\\RedisStore\n        && $store->hasSeparateLockStore();\n}","tryCatchPattern":"try {\n    Cache::store('redis')->getStore()->flushLocks();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'lock store is separate')) {\n        Cache::store('redis')->flush();\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Configure lock_connection in every redis cache store.","Use a dedicated Redis database (e.g. database => 1) for locks.","Guard hasSeparateLockStore() before flushLocks().","Document the lock connection in deployment runbooks."],"tags":["cache","redis-store","locks","configuration"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}