{"record":{"id":"61d661df4320ec5d","repo":"microsoft/qlib","slug":"it-sees-the-key-lock-repr-lock-name-1-1-wlock","errorCode":null,"errorMessage":"It sees the key(lock:{repr(lock_name)[1:-1]}-wlock) of the redis lock has existed in your redis db now.\n                    You can use the following command to clear your redis keys and rerun your commands:\n                    $ redis-cli\n                    > select {C.redis_task_db}\n                    > del \"lock:{repr(lock_name)[1:-1]}-wlock\"\n                    > quit\n                    If the issue is not resolved, use \"keys *\" to find if multiple keys exist. If so, try using \"flushall\" to clear all the keys.\n                ","messagePattern":"It sees the key\\(lock:(.+?)-wlock\\) of the redis lock has existed in your redis db now\\.\n                    You can use the following command to clear your redis keys and rerun your commands:\n                    \\$ redis-cli\n                    > select (.+?)\n                    > del \"lock:(.+?)-wlock\"\n                    > quit\n                    If the issue is not resolved, use \"keys \\*\" to find if multiple keys exist\\. If so, try using \"flushall\" to clear all the keys\\.\n                ","errorType":"exception","errorClass":"QlibCacheException","httpStatus":null,"severity":"error","filePath":"qlib/data/cache.py","lineNumber":245,"sourceCode":"            meta_path = cache_path.with_suffix(\".meta\")\n            with meta_path.open(\"rb\") as f:\n                d = restricted_pickle_load(f)\n            with meta_path.open(\"wb\") as f:\n                try:\n                    d[\"meta\"][\"last_visit\"] = str(time.time())\n                    d[\"meta\"][\"visits\"] = d[\"meta\"][\"visits\"] + 1\n                except KeyError as key_e:\n                    raise KeyError(\"Unknown meta keyword\") from key_e\n                pickle.dump(d, f, protocol=C.dump_protocol_version)\n        except Exception as e:\n            get_module_logger(\"CacheUtils\").warning(f\"visit {cache_path} cache error: {e}\")\n\n    @staticmethod\n    def acquire(lock, lock_name):\n        try:\n            lock.acquire()\n        except redis_lock.AlreadyAcquired as lock_acquired:\n            raise QlibCacheException(\n                f\"\"\"It sees the key(lock:{repr(lock_name)[1:-1]}-wlock) of the redis lock has existed in your redis db now.\n                    You can use the following command to clear your redis keys and rerun your commands:\n                    $ redis-cli\n                    > select {C.redis_task_db}\n                    > del \"lock:{repr(lock_name)[1:-1]}-wlock\"\n                    > quit\n                    If the issue is not resolved, use \"keys *\" to find if multiple keys exist. If so, try using \"flushall\" to clear all the keys.\n                \"\"\"\n            ) from lock_acquired\n\n    @staticmethod\n    @contextlib.contextmanager\n    def reader_lock(redis_t, lock_name: str):\n        current_cache_rlock = redis_lock.Lock(redis_t, f\"{lock_name}-rlock\")\n        current_cache_wlock = redis_lock.Lock(redis_t, f\"{lock_name}-wlock\")\n        lock_reader = f\"{lock_name}-reader\"\n        # make sure only one reader is entering\n        current_cache_rlock.acquire(timeout=60)","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/data/cache.py#L227-L263","documentation":"Error \"It sees the key(lock:{repr(lock_name)[1:-1]}-wlock) of the redis lock has existed in your redis db now.\n                    You can use the following command to clear your redis keys and rerun your commands:\n                    $ redis-cli\n                    > select {C.redis_task_db}\n                    > del \"lock:{repr(lock_name)[1:-1]}-wlock\"\n                    > quit\n                    If the issue is not resolved, use \"keys *\" to find if multiple keys exist. If so, try using \"flushall\" to clear all the keys.\n                \" thrown in microsoft/qlib.","triggerScenarios":"This error is raised at qlib/data/cache.py:245 when the guard condition fails: \"redis lock key already exists\". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.","commonSituations":"See trigger scenarios.","solutions":["Clear the stale redis lock: run redis-cli, `select <redis_task_db>`, then `del \"lock:<name>-wlock\"`, and rerun your command.","If multiple stale keys exist, use `keys *` to inspect and `flushall` to clear all keys, then rerun."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}