I have promisified the code of caching dataand pushing the array of Json values in the new array but after the chaining, array is showing undefined. Here is the code snippet.
'use strict';
const Promise = require('bluebird');
let _connectResolve, _connectReject, onConnected = new Promise((resolve, reject) => {
_connectResolve = resolve;
_connectReject = reject;
}),
redis = require("redis"),
redisClient = redis.createClient({
host: 'localhost',
port: 6379
});
Promise.promisifyAll(redis.RedisClient.prototype);
redisClient.on('connect', _connectResolve);
const results = Promise.all([
'iems/0I0g2I92u0U3k/120s.zip',
'ims/25213u0X462g/10es.zip',
'ims/2x0n440V1A0f1K/F.zip',
'its/2l0239311f1u0w1S2a3j/Files.zip',
'its/2O2x212i0a2f1j3t0B2h/Files.zip',
]);
onConnected.then(() => {
var message = [];
results.map(function(result) {
redisClient.getAsync(result).then((reply) => {
return new Promise((resolve, reject) => {
resolve({
'response': reply,
'req': result
});
});
}).then(function(reply) {
if (reply['response'] != true) {
message.push({
"key": reply['req'],
"bucket_name": 'string here'
});
}
});
}).then(function(){console.log(message)});
});
Conclusion -> message is undefined