Skip to content

[WIP] Add the Ability to use Redis for Storage #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Prev Previous commit
Next Next commit
Add redis errors to the log
pseudomuto committed Oct 3, 2016

Verified

This commit was signed with the committer’s verified signature.
pseudomuto David Muto
commit 07bfe07651d975ab49d92ba93a030e1a24af292c
15 changes: 15 additions & 0 deletions lib/store/redis.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var log = require("winston");
var redis = require("redis");

var DEFAULT_HOST = "127.0.0.1";
@@ -58,6 +59,12 @@ function firstDefinedIndex (targets) {
return -1;
}

function logErr(err) {
if (err) {
log.error("REDIS error:", err);
}
}

exports.create = function (BaseStore, host, port, db) {
var client = createClient(host, port, db);

@@ -67,6 +74,7 @@ exports.create = function (BaseStore, host, port, db) {
var that = this;

client.hgetall(path, function (err, res) {
logErr(err);
that.notify(cb, expand(res) || undefined);
});
}
@@ -81,6 +89,7 @@ exports.create = function (BaseStore, host, port, db) {
keys.forEach(function (key) { multi.hgetall(key); });

multi.exec(function (err, values) {
logErr(err);
if (err || values.length === 0) {
that.notify(cb);
return;
@@ -102,6 +111,7 @@ exports.create = function (BaseStore, host, port, db) {
var that = this;

client.keys("*", function (err, keys) {
logErr(err);
if (err || keys.length === 0) {
that.notify(cb, {});
return;
@@ -114,6 +124,7 @@ exports.create = function (BaseStore, host, port, db) {
keys.forEach(function (key) { multi.hgetall(key); });

multi.exec(function (err, values) {
logErr(err);
keys.forEach(function (key, index) {
routes[key] = expand(values[index]);
});
@@ -128,6 +139,7 @@ exports.create = function (BaseStore, host, port, db) {
var that = this;

client.hmset(path, scrub(data), function (err, res) {
logErr(err);
that.notify(cb);
});
}
@@ -138,6 +150,7 @@ exports.create = function (BaseStore, host, port, db) {

this.get(path, function (current) {
client.hmset(path, Object.assign(current, scrub(data)), function (err, res) {
logErr(err);
that.notify(cb);
});
});
@@ -148,6 +161,7 @@ exports.create = function (BaseStore, host, port, db) {
var that = this;

client.del(path, function (err, res) {
logErr(err);
that.notify(cb);
});
}
@@ -157,6 +171,7 @@ exports.create = function (BaseStore, host, port, db) {
var that = this;

client.exists(path, function (err, res) {
logErr(err);
that.notify(cb, res === 1);
});
}