gpt4 book ai didi

node.js - Redis 在 nodejs 中太慢?

转载 作者:可可西里 更新时间:2023-11-01 11:23:25 24 4
gpt4 key购买 nike

在 nodejs 上使用 connect-redis 太慢了。当我将 connect-redis 连接到应用程序时性能下降

const RedisStore = require('connect-redis')(session);
...
app1.use(session({
store: new RedisStore(
config.redisStore
),
secret: 'asd',
resave: false,
rolling: true,
saveUninitialized: false,
cookie: {
maxAge: config.redisStore.maxAge,
httpOnly:false,
},
}));

如果我在 apache bench 上的应用程序中没有这段代码,我每秒大约有 3600 个请求。使用它的代码 - 大约 2500。nodejs 中的测试路由仅发送“OK”

为什么只创建 RedisStore 的“实例”会导致性能下降?

在应用中我不直接使用redistore

最佳答案

我建议你使用 ioredis npm ( https://www.npmjs.com/package/ioredis )

如果要发送一批命令(例如> 5),可以使用流水线将命令在内存中排队,然后一次性发送到Redis。这样性能提升了50%~300%。

关于node.js - Redis 在 nodejs 中太慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56718163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com