-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
44 lines (32 loc) · 970 Bytes
/
index.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
40
41
42
43
44
var eel = require('eel')
eel.backends.register('redis:', createBackend)
module.exports = createBackend
var redis = require('redis')
function createBackend (uri) {
var port = uri.port || 6379
, host = uri.hostname || 'localhost'
, client = redis.createClient(port, host)
, db
;
if (uri.auth) client.auth(uri.auth)
if (uri.query && (db = parseInt(uri.query.db)) && !isNaN(db)) client.select(db)
function onError (err) {
var msg = 'Redis client emitted error: ' + err
var fields = {
uri: uri.href,
err: err,
stack: err.stack.split('\n').map(function (l) { return l.trim() }),
}
if (err.code == 'ECONNREFUSED') eel.backends.unload(handler)
else reconnect()
eel.error(msg, fields)
}
var list = uri.query.list || 'logstash'
function handler (entry) {
var output = eel.formatter.safeJSON(entry)
if (output) client.rpush(list, output)
}
handler.client = client
handler.end = function () { client.quit() }
return handler
}