I have a program that wants to read data from an API and compare that data with data stored in the database. if some conditions exist, then remove data from the database and send data to a function. Database and API are not important for me in this example but if you want to know, I'm working with "node-binance-api" and Redis database and Node.js.
REDIS_PORT = process.env.PORT || 6379;
redisClient = createClient(this.REDIS_PORT);
binance.futuresMiniTickerStream((miniTicker) => {
miniTicker.forEach((_array) => {
_array.forEach((selectedPair) => {
redis.ZRANG(`binance-future-${selectedPair.symbol}`, (obj) => {
obj.forEach(item => {
item = JSON.parse(item);
if (item.targetPrice > item.firstPrice && selectedPair.close >= item.targetPrice || item.targetPrice < item.firstPrice && selectedPair.close <= item.targetPrice) {
redisClient.ZREMRANGEBYSCORE(`binance-future-${selectedPair.symbol}`, item.targetPrice, item.targetPrice, () => {
console.log("Item Deleted");
})
}
});
});
});
});
});
how can I optimize this piece of code? also for some optimization operations, I wanna use RabbitMQ to distribute my code to some workers, I used RabbitMQ before in this project, but any idea, I'm happy to read.