隐藏

Node.js 连接redis时报错:The client is closed

发布:2023/11/1 22:18:10作者:管理员 来源:本站 浏览次数:655

1.贴一下报错信息


   (node:8256) UnhandledPromiseRejectionWarning: Error: The client is closed

       at RedisSocket.quit (D:\node.js\node_modules\@redis\client\dist\lib\client\socket.js:72:19)

       at Commander.QUIT (D:\node.js\node_modules\@redis\client\dist\lib\client\index.js:222:71)

       at Object.<anonymous> (D:\node.js\redis\redis.js:19:8)

       at Module._compile (internal/modules/cjs/loader.js:1063:30)

       at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

       at Module.load (internal/modules/cjs/loader.js:928:32)

       at Function.Module._load (internal/modules/cjs/loader.js:769:14)

       at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)

       at internal/main/run_main_module.js:17:47

   (Use `node --trace-warnings ...` to show where the warning was created)

   (node:8256) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was no

   t handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).

   (rejection id: 3)

   (node:8256) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

   (node:8256) UnhandledPromiseRejectionWarning: Error: The client is closed

       at Commander._RedisClient_sendCommand (D:\node.js\node_modules\@redis\client\dist\lib\client\index.js:404:31)

       at Commander.commandsExecutor (D:\node.js\node_modules\@redis\client\dist\lib\client\index.js:167:154)

       at Commander.BaseClass.<computed> [as set] (D:\node.js\node_modules\@redis\client\dist\lib\commander.js:8:29)

       at Object.<anonymous> (D:\node.js\redis\redis.js:13:8)

       at Module._compile (internal/modules/cjs/loader.js:1063:30)

       at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

       at Module.load (internal/modules/cjs/loader.js:928:32)

       at Function.Module._load (internal/modules/cjs/loader.js:769:14)

       at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)

       at internal/main/run_main_module.js:17:47

   (node:8256) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was no

   t handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).

   (rejection id: 4)

   (node:8256) UnhandledPromiseRejectionWarning: Error: The client is closed

       at Commander._RedisClient_sendCommand (D:\node.js\node_modules\@redis\client\dist\lib\client\index.js:404:31)

       at Commander.commandsExecutor (D:\node.js\node_modules\@redis\client\dist\lib\client\index.js:167:154)

       at Commander.BaseClass.<computed> [as get] (D:\node.js\node_modules\@redis\client\dist\lib\commander.js:8:29)

       at Object.<anonymous> (D:\node.js\redis\redis.js:16:8)

       at Module._compile (internal/modules/cjs/loader.js:1063:30)

       at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

       at Module.load (internal/modules/cjs/loader.js:928:32)

       at Function.Module._load (internal/modules/cjs/loader.js:769:14)

       at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)

       at internal/main/run_main_module.js:17:47

   (node:8256) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was no

   t handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).

   (rejection id: 5)


2.出现这个问题的原因:应该是你npm install 默认安装的Redis client for Node.js为V4.0.0版本,一些接口已经改变了,所以导致报错。


3.解决方法:回退redis的版本


回退到node-redis v3.1.2


   npm uninstall --save redis

   npm install --save redis@3.1.2


4.然后重新执行一下你的文件,可以成功运行了。