我正在尝试运行一个从Redis中提取并插入数据库的简单程序。这个程序似乎永远不会退出,有人能指出我正确的方向吗?
require('newrelic')
const client = require('./config/redis')
const models = require('./models')
const sequelize = require('sequelize')
async function flushTweets() {
try {
var tweets = await client.lrangeAsync('writer', 0, 100)
client.ltrim('writer', 0, 100)
if (tweets && tweets.length > 0) {
tweets = tweets.map(tweet => JSON.parse(tweet))
models.Tweet.bulkCreate(tweets, { returning: true });
for (var i = 0; i < tweets.length; ++i) {
models.User.update(
{ numTweets: sequelize.literal(`"Users"."numTweets" + 1`) },
{ where: { id: tweets[i].user.id }
});
}
}
} catch (e) {
}
}
flushTweets();