核心提示:ClientClosedError: The client is closed
已经解决: "redis": "^4.7.0", —— 4的版本和3引入 redis不一样了。将require('redis') 改成require('ioredis'),解决了。
<-- GET /square
/Users/ann/Documents/Nodejs/wbproject/kwc/node_modules/@redis/client/dist/lib/client/index.js:520
return Promise.reject(new errors_1.ClientClosedError());
^
ClientClosedError: The client is closed
at Commander._RedisClient_sendCommand (/Users/ann/Documents/Nodejs/wbproject/kwc/node_modules/@redis/client/dist/lib/client/index.js:520:31)
at Commander.commandsExecutor (/Users/ann/Documents/Nodejs/wbproject/kwc/node_modules/@redis/client/dist/lib/client/index.js:190:154)
at BaseClass.<computed> [as get] (/Users/ann/Documents/Nodejs/wbproject/kwc/node_modules/@redis/client/dist/lib/commander.js:8:29)
** at /Users/ann/Documents/Nodejs/wbproject/kwc/src/cache/_redis.js:37:21
at new Promise (<anonymous>)
at get **(/Users/ann/Documents/Nodejs/wbproject/kwc/src/cache/_redis.js:36:21)
检查了代码;没问题。代码如下:
const redisClient = redis.createClient(REDIS_CONF.port, REDIS_CONF.host)
redisClient.on('error', err => {
console.error('Redis error: ',err)
})
package文件也有
redis ,
"dependencies": {
"ajv": "^8.17.1",
"debug": "^4.1.1",
"ejs": "~2.3.3",
"formidable-upload-koa": "^1.0.1",
"fs-extra": "^11.3.0",
"koa": "^2.7.0",
"koa-bodyparser": "^4.2.1",
"koa-convert": "^1.2.0",
"koa-generic-session": "^2.3.1",
"koa-json": "^2.0.2",
"koa-logger": "^3.2.0",
"koa-onerror": "^4.1.0",
"koa-redis": "^4.0.1",
"koa-router": "^7.4.0",
"koa-static": "^5.0.0",
"koa-views": "^6.2.0",
"mysql2": "^3.12.0",
"redis": "^4.7.0",
"sequelize": "^6.37.5",
"xss": "^1.0.15"
},
redis,keys 也有数据:
127.0.0.1:6379> keys *
1) "wbs.sessbuwR0EyEe3M6sx5jbJwxFXPQLDXktheJ"
2) "wbs.sess60hQWxlju3KofqzhmN_4ADd2C7LLLNoA"
3) "wbs.sess9hwiMnbO_fdNBoiHeHNcBJhm-8pmB810"
4) "wbs.sessO4z7ac5u9W4gYa_fg2ndzvPI-_ZgHq3D"
5) "wbs.sessu2LXMu1O8GVfR2dmaFgoXwsn7ewlt6wi"
6) "wbs.sessTzXu2b7gaTtXaRSrlT13SHhNXxHH-3L-"
7) "wbs.sess4G3UfaTpgvv-YCavfMkvhIoLMa3RKlE5"
8) "wbs.sessdgRBwy7Lb6QU0zjki3FY7Vk6-yB1-_h2"
9) "wbs.sesss5trw7ZxSn4WEDTfMSl7zg143QMWXvyR"
10) "wbs.sess9lU9c9mRKlwl3aBvcPscDS0ebMNqqj9c"
11) "wbs.sessHjm7CRpL4EwikPYVEnyIZSZgjAm79Tnc"
12) "wbs.sess9NfGiwbyI7dUsA29br0q0bGN95s_nDDx"
13) "wbs.sessc9KyWYo9cQazo2G6UR7-E-Y3fecxzbqt"
14) "wbs.sess4p_QWkY2tIfURR-dXQVkXwAnB4a81IA-"
15) "wbs.sessKnfVjT9I6ekCEAVUxfNzOSVSWQNQeK4G"
127.0.0.1:6379>