【发布时间】:2019-03-05 09:47:11
【问题描述】:
初始值集发生在服务器上 (\complex\server\index.js):
app.post('/values', async (req, res) => {
const index = req.body.index;
if (parseInt(index) > 40) {
return res.status(422).send('Index too high');
}
redisClient.hset('values', index, 'Nothing yet!');
redisPublisher.publish('insert', index);
pgClient.query('INSERT INTO values(number) VALUES($1)', [index]);
res.send({ working: true });
});
在组件中提交值(\complex\client\src\Fib.js):
handleSubmit = async (event) => {
event.preventDefault();
await axios.post('/api/values', {
index: this.state.index
});
this.setState({ index: '' });
};
worker 为 Redis 客户端设置值:
sub.on('message', (channel, message) => {
redisClient.hset('values', message, fib(parseInt(message)));
});
sub.subscribe('insert');
但是,当为每个提交的索引列出 Fib.js 组件内的所有值时,组件会收到“还没有!”。
为什么它不接收计算值? 完整的 repo 在https://github.com/ElAnonimo/docker-complex
【问题讨论】:
标签: redis node-redis