setInterval(() => { const currentSpeed = getCurrentSpeed(); const currentRPM = getCurrentRPM(currentSpeed); redis.lpush(speedListKey, currentSpeed); redis.lpush(rpmListKey, currentRPM); redis.zincrby(speedSetKey, 1, currentSpeed); redis.zincrby(rpmSetKey, 1, currentRPM); });
var setNoti = function(data){ log.info('setNoti',data); cluster.hmset('noti', data, function(err, res){ if(err) log.warn(err); else log.info(data); }); };
process.on('SIGINT', () => { console.log('\nClosing producer connection'); kafkaClient.close(); producer.close(); redis.disconnect(); process.exit(); });
clear: function () { cacheRedis.flushall(function (err) { if (err) { util.log('cacheHelper.clear', err); } else { util.log('cacheHelper.clear', 'ok'); } }); },
keys.forEach(function (key) { cacheRedis.del(key, function (err) { if (err) { util.log('cacheHelper.remove', key, err); } else { callback && callback(); } }); });
_get: function (key, callback) { cacheRedis.get(key, function (err, res) { if (err) { util.log('cacheHelper._get', key, err); } else { callback && callback(res); } }); },
cluster.exists('noti', function(err, res){ if(res == 1){ cluster.hgetall('noti', function(err, res){ log.warn(err); socket.emit('getData', {title: res.title, link: res.link}); }); }else{ socket.emit('getData', {title: 'not exists', link: 'http://null.com'}); } });
}], (error, data) => { if (error) { // console.error(`Could not produce message:\n${error}\nRetrying...`); tries++; } else { redis.incr('massproduce'); success = true; } callback(); });
set: function (key, value, callback) { value = typeof value == 'object' ? JSON.stringify(value) : value; cacheRedis.set(key, value, function (err) { if (err) { util.log('cacheHelper.set', key, err); } else { util.log('cacheHelper.set', key, value); callback && callback(); } }); },
setInterval(() => { const currentSpeed = getCurrentSpeed(); const currentRPM = getCurrentRPM(currentSpeed); redis.lpush(speedListKey, currentSpeed); redis.lpush(rpmListKey, currentRPM); redis.zincrby(speedSetKey, 1, currentSpeed); redis.zincrby(rpmSetKey, 1, currentRPM); redis.publish('lpush', JSON.stringify({ key: speedSetKey, value: currentSpeed })); redis.publish('lpush', JSON.stringify({ key: rpmSetKey, value: currentRPM })); redis.publish('zincr', ''); redis.publish('zincr', ''); });
port: 6379, host: process.env.REDIS_CONNECTION_2 }, { port: 6379, host: process.env.REDIS_CONNECTION_3 }, { port: 6379, host: process.env.REDIS_CONNECTION_4 }, { port: 6379, host: process.env.REDIS_CONNECTION_5 }, { port: 6379, host: process.env.REDIS_CONNECTION_6 }]; const redis = new Redis.Cluster(hosts); redis.set('massproduce', 0); function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } let message = ''; function buildMessage(size) {