-
Notifications
You must be signed in to change notification settings - Fork 2
/
az_redis.js
39 lines (33 loc) · 879 Bytes
/
az_redis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'esversion: 6';
const debug = require('debug')('nbiot_cloud_gw')
const name = 'redis-server'
var redis = require("redis");
const settings = require('./data/config.json');
var redis_client = redis.createClient(6380, settings.redis.url, {
auth_pass: settings.redis.key,
tls: {
servername: settings.redis.url
}
});
redis_client.on('connect', function () {
redis_client.auth(settings.redis.key, (err) => {
if (err) debug(err);
else debug(`${name} spawned: ${process.pid}`);
})
});
process.on('message', (msg) => {
switch (msg.type) {
case 'cache_write':
debug(name + ': [master] cache write ---> [az_redis] ');
let payload = JSON.parse(msg.payload)
payload['timestamp'] = new Date().toISOString();
let val = JSON.stringify(payload)
redis_client.set(
msg.deviceId,
val);
break;
default:
break;
}
});
module.exports = redis_client;