Commit 1a5a3629d73f4a3f84c55ee86387f6ab799bf4f6
1 parent
eb0629a0ec
Exists in
master
Load history from redis on start
Showing 1 changed file with 9 additions and 1 deletions Side-by-side Diff
lib/history.js
... | ... | @@ -4,6 +4,8 @@ const redis = require('redis'); |
4 | 4 | const CircularBuffer = require("circular-buffer"); |
5 | 5 | |
6 | 6 | const config = require('komodo-sdk/config'); |
7 | +const logger = require('komodo-sdk/logger'); | |
8 | + | |
7 | 9 | const redisClient = redis.createClient(config.redis || { host: '127.0.0.1' }); |
8 | 10 | const history = new CircularBuffer(1000); |
9 | 11 | |
... | ... | @@ -11,7 +13,13 @@ const REDIS_KEYWORD = `SHAKIR_SMS_HISTORY_${config.name||'SMS'}`; |
11 | 13 | |
12 | 14 | function fetchFromRedis() { |
13 | 15 | redisClient.LRANGE(REDIS_KEYWORD, 0, -1, (err, reply) => { |
14 | - console.log(reply); | |
16 | + reply.forEach((el) => { | |
17 | + try { | |
18 | + history.push(JSON.parse(el)); | |
19 | + } catch (e) { | |
20 | + logger.warn(`Error parsing JSON on redis history. ${e.toString()}`); | |
21 | + } | |
22 | + }); | |
15 | 23 | }) |
16 | 24 | } |
17 | 25 | fetchFromRedis(); |